A high-performance, zero-overhead, extensible Python compiler using LLVM
 
 
 
 
 
Go to file
A. R. Shajii d5ce1f8ff9
Update docs (#28)
* Update docs

* Update docs

* Update docs

* GitBook: [#4] Add hint

* Update primer

* Re-organize docs

* Fix table

* Fix link

* GitBook: [#5] No subject

* GitBook: [#6] No subject

* Cleanup and doc fix

* Add IR docs

* Add ir docs

* Fix spelling error

* More IR docs

* Update README.md

* Update README.md

* Fix warning

* Update intro

* Update README.md

* Update docs

* Fix table

* Don't build docs

* Update docs

* Add Jupyter docs

* FIx snippet

* Update README.md

* Fix images

* Fix code block

* Update docs, update cmake

* Break up tutorial

* Update pipeline.svg

* Update docs for new version

* Add differences with Python docs
2022-07-26 16:08:42 -04:00
.github Typechecker refactoring (#20) 2022-07-26 16:06:00 -04:00
cmake Full regex implementation (#38) 2022-07-08 23:17:50 +00:00
codon Update docs (#28) 2022-07-26 16:08:42 -04:00
docs Update docs (#28) 2022-07-26 16:08:42 -04:00
extra Cython package (#34) 2022-06-26 17:38:29 -04:00
scripts Refactor build files 2021-10-10 01:02:11 -04:00
stdlib Typechecker refactoring (#20) 2022-07-26 16:06:00 -04:00
test Typechecker refactoring (#20) 2022-07-26 16:06:00 -04:00
.clang-format Initial commit 2021-09-27 14:02:44 -04:00
.clang-tidy Typechecker refactoring (#20) 2022-07-26 16:06:00 -04:00
.gitattributes Update .gitattributes 2021-10-03 11:18:57 -04:00
.gitignore Typechecker refactoring (#20) 2022-07-26 16:06:00 -04:00
CMakeLists.txt Update docs (#28) 2022-07-26 16:08:42 -04:00
CODEOWNERS Initial commit 2021-09-27 14:02:44 -04:00
CONTRIBUTING.md Update docs (#1) 2021-10-05 10:12:56 -05:00
README.md Update docs (#28) 2022-07-26 16:08:42 -04:00
book.json Update docs (#28) 2022-07-26 16:08:42 -04:00

README.md

Codon

Build Status Discord

What is Codon?

Think of Codon as a strongly-typed and statically-compiled Python: all the bells and whistles of Python, boosted with a strong type system, without any performance overhead.

Codon is a high-performance Python compiler that compiles Python code to native machine code without any runtime overhead. Typical speedups over Python are on the order of 10-100x or more, on a single thread. Codon's performance is typically on par with (and in many cases better than) that of C/C++. Unlike Python, Codon supports native multithreading, which can lead to speedups many times higher still.

Codon is extensible via a plugin infrastructure. For example, Seq is a domain-specific language for genomics and bioinformatics, built on Codon, that can outperform hand-optimized C code by 2-10x (more details in the Seq paper).

What isn't Codon?

While Codon supports nearly all of Python's syntax, it is not a drop-in replacement, and large codebases might require modifications to be run through the Codon compiler. For example, some of Python's modules are not yet implemented within Codon, and a few of Python's dynamic features are disallowed. The Codon compiler produces detailed error messages to help identify and resolve any incompatibilities.

Codon supports seamless Python interoperability to handle cases where specific Python libraries or dynamism are required:

@python
def hello():
    import sys
    print('Hello from Python!')
    print('The version is', sys.version)

hello()
# Hello from Python!
# The version is 3.9.6 (default, Jun 29 2021, 06:20:32)
# [Clang 12.0.0 (clang-1200.0.32.29)]

Examples

Codon is a Python-compatible language, and many Python programs will work with few if any modifications:

def fib(n):
    a, b = 0, 1
    while a < n:
        print(a, end=' ')
        a, b = b, a+b
    print()
fib(1000)

This prime counting example showcases Codon's OpenMP support, enabled with the addition of one line. The @par annotation tells the compiler to parallelize the following for-loop, in this case using a dynamic schedule, chunk size of 100, and 16 threads.

from sys import argv

def is_prime(n):
    factors = 0
    for i in range(2, n):
        if n % i == 0:
            factors += 1
    return factors == 0

limit = int(argv[1])
total = 0

@par(schedule='dynamic', chunk_size=100, num_threads=16)
for i in range(2, limit):
    if is_prime(i):
        total += 1

print(total)

Install

Pre-built binaries

Pre-built binaries for Linux and macOS on x86_64 are available alongside each release. We also have a script for downloading and installing pre-built versions:

/bin/bash -c "$(curl -fsSL https://exaloop.io/install.sh)"

Build from source

See Building from Source.

Documentation

Please see docs.exaloop.io for in-depth documentation.