gitmyhub

codon

Python ★ 17k updated 2d ago

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

A Python compiler built on LLVM that turns Python-like code into native machine code, dropping the GIL and adding multi-threading and GPU support for big speedups.

PythonLLVMC++CUDAsetup: moderatecomplexity 4/5

Codon is a Python compiler that translates Python code into native machine code, giving it the performance of a compiled language like C or C++ while keeping Python's familiar syntax. Standard Python runs code through an interpreter, adding overhead that makes it much slower for computation-heavy tasks. Codon removes that overhead by compiling ahead of time.

The speed difference can be dramatic. The README shows a benchmark where the same recursive Fibonacci calculation takes about 18 seconds in standard Python and 0.28 seconds in Codon — roughly a 65x speedup. NumPy-based code also runs significantly faster.

Beyond raw speed, Codon removes Python's GIL — the Global Interpreter Lock, which normally prevents Python code from using multiple CPU cores simultaneously. Codon supports true multi-threading using a parallel annotation you add to loops, specifying how many threads to use and how to divide up the work. It also supports writing GPU kernels, letting you run computations on a graphics card directly from Python-like code.

Codon is not a complete drop-in replacement for Python: some dynamic features of standard Python do not work in a statically compiled system. However, you can call standard Python libraries from Codon when needed, and use Codon selectively inside larger Python projects via a decorator that compiles specific functions. Codon includes a fully compiled implementation of NumPy, the popular numerical computing library, and is built on LLVM — the same compiler infrastructure used by C and C++ compilers.

You would use Codon when you have Python code doing heavy number crunching and want much faster execution without rewriting in another language.

Where it fits