back to home

exaloop / codon

A high-performance, zero-overhead, extensible Python compiler with built-in NumPy support

16,676 stars
594 forks
97 issues
PythonC++C

AI Architecture Analysis

This repository is indexed by RepoMind. By analyzing exaloop/codon in our AI interface, you can instantly generate complete architecture diagrams, visualize control flows, and perform automated security audits across the entire codebase.

Our Agentic Context Augmented Generation (Agentic CAG) engine loads full source files into context on-demand, avoiding the fragmentation of traditional RAG systems. Ask questions about the architecture, dependencies, or specific features to see it in action.

Source files are only loaded when you start an analysis to optimize performance.

Embed this Badge

Showcase RepoMind's analysis directly in your repository's README.

[![Analyzed by RepoMind](https://img.shields.io/badge/Analyzed%20by-RepoMind-4F46E5?style=for-the-badge)](https://repomind.in/repo/exaloop/codon)
Preview:Analyzed by RepoMind

Repository Overview (README excerpt)

Crawler view

Docs  ·  FAQ  ·  Blog  ·  Discord  ·  Roadmap  ·  Benchmarks What is Codon? Codon is a high-performance Python implementation that compiles to native machine code without any runtime overhead. Typical speedups over vanilla Python are on the order of 10-100x or more, on a single thread. Codon's performance is typically on par with (and sometimes better than) that of C/C++. Unlike Python, Codon supports native multithreading, which can lead to speedups many times higher still. *Think of Codon as Python reimagined for static, ahead-of-time compilation, built from the ground up with best possible performance in mind.* Goals • :bulb: **No learning curve:** Be as close to CPython as possible in terms of syntax, semantics and libraries • :rocket: **Top-notch performance:** At *least* on par with low-level languages like C, C++ or Rust • :computer: **Hardware support:** Full, seamless support for multicore programming, multithreading (no GIL!), GPU and more • :chart_with_upwards_trend: **Optimizations:** Comprehensive optimization framework that can target high-level Python constructs and libraries • :battery: **Interoperability:** Full interoperability with Python's ecosystem of packages and libraries Non-goals • :x: *Drop-in replacement for CPython:* Codon is not a drop-in replacement for CPython. There are some aspects of Python that are not suitable for static compilation — we don't support these in Codon. There are ways to use Codon in larger Python codebases via its JIT decorator or Python extension backend. Codon also supports calling any Python module via its Python interoperability. See also *"Differences with Python"* in the docs. • :x: *New syntax and language constructs:* We try to avoid adding new syntax, keywords or other language features as much as possible. While Codon does add some new syntax in a couple places (e.g. to express parallelism), we try to make it as familiar and intuitive as possible. How it works Quick start Download and install Codon with this command: After following the prompts, the command will be available to use. For example: • To run a program: • To run a program with optimizations enabled: • To compile to an executable: • To generate LLVM IR: Many more options are available and described in the docs. Alternatively, you can build from source. Examples Basics Codon supports much of Python, and many Python programs will work with few if any modifications. Here's a simple script that computes the 40th Fibonacci number... ... run through Python and Codon: Using Python libraries You can import and use any Python package from Codon via . For example: (Just remember to set the environment variable to the CPython shared library, as explained in the the Python interoperability docs.) Parallelism Codon supports native multithreading via OpenMP. The annotation in the code below tells the compiler to parallelize the following -loop, in this case using a dynamic schedule, chunk size of 100, and 16 threads. Note that Codon automatically turns the statement in the loop body into an atomic reduction to avoid race conditions. Learn more in the multithreading docs. Codon also supports writing and executing GPU kernels. Here's an example that computes the Mandelbrot set: GPU programming can also be done using the syntax with . See the GPU programming docs for more details. NumPy support Codon includes a feature-complete, fully-compiled native NumPy implementation. It uses the same API as NumPy, but re-implements everything in Codon itself, allowing for a range of optimizations and performance improvements. Here's an example NumPy program that approximates $\pi$ using random numbers... ... run through Python and Codon: Codon can speed up NumPy code through general-purpose and NumPy-specific compiler optimizations, including inlining, fusion, memory allocation elision and more. Furthermore, Codon's NumPy implementation works with its multithreading and GPU capabilities, and can even integrate with PyTorch. Learn more in the Codon-NumPy docs. Documentation Please see docs.exaloop.io for in-depth documentation. Acknowledgements This project would not be possible without: • **Funding**: • National Science Foundation (NSF) 🇺🇸 • National Institutes of Health (NIH) 🇺🇸 • MIT 🇺🇸 • MIT E14 Fund 🇺🇸 • Natural Sciences and Engineering Research Council (NSERC) 🇨🇦 • Canada Research Chairs 🇨🇦 • Canada Foundation for Innovation 🇨🇦 • B.C. Knowledge Development Fund 🇨🇦 • University of Victoria 🇨🇦 • **Libraries**: LLVM Compiler Infrastructure, yhirose's peglib, Boehm-Demers-Weiser Garbage Collector, KonanM's tser, {fmt}, toml++, semver, zlib-ng, xz, bz2, Google RE2, libbacktrace, fast_float, Google Highway, NumPy