Codon, a new high-performance Python compiler 

lonely

Codon is a high performance Python compiler that compiles Python code to native machine code.

Recently the startup Exaloop unveiled through a tweet the release of the project code Codon, who develops a compiler for the Python language which can generate pure machine code as output, not tied to the Python runtime.

The compiler is developed by the authors of the Python-like Seq language and is positioned as a continuation of its development. The project also offers its own runtime for executable files and a function library that replaces library calls in the Python language.

About Codon

Performance of the output executables It is promoted as being close to programs written in the C language. Compared to using CPython, the performance gain when compiling with Codon is estimated to be 10-100 times for single-threaded execution. At the same time, unlike Python, Codon additionally implements the possibility of using multithreading, which allows you to achieve an even greater increase in performance. codon also allows you to compile at the function level to use the compiled view in existing Python projects.

codon is built using a modular architecture which allows you to extend functionality through plugins that can add new libraries, implement compiler optimizations, and even provide support for additional syntax.

For example, several plugins are being developed in parallel for use in bioinformatics and financial mathematics. The Boehm garbage collector is used for memory management.

the compiler supports most of the Python syntax, but compiling into native code imposes a number of limitations that prevent Codon from being used as a transparent replacement for CPython. For example, Codon uses the 64-bit int type for integers, while CPython has unlimited integers.

Codon support for large code bases may require code changes. Incompatibilities are typically caused by the lack of Codon implementation of certain Python modules and the inability to use some of the language's dynamic features. For each of these incompatibilities, the compiler issues a detailed diagnostic message with information on how to fix the problem.

The compiler, runtime, and standard library source code is written with C++ (using LLVM developments) and Python, and is distributed under the BSL license (Business Source License). The essence of BSL is that the extended functionality code is initially available for modification, but for some time it can be used free of charge only subject to additional conditions, which require the purchase of a commercial license to bypass.

The Codon project's additional license terms require that the code be transferred to the Apache License 2.0 after 3 years (November 1, 2025). Until then, the license allows copying, distribution, and modification, as long as it is used for non-commercial purposes.

How to install Codon on Linux?

For those interested in being able to install this compiler, they should know that they can do it quite easily, just open a terminal and execute the following command that will download and install the installation script:

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

As for those interested in being able to compile on their own, they can do so by running the following commands:

git clone --depth 1 -b codon https://github.com/exaloop/llvm-project
cmake -S llvm-project/llvm -B llvm-project/build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_INCLUDE_TESTS=OFF \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_ENABLE_ZLIB=OFF \
-DLLVM_ENABLE_TERMINFO=OFF \
-DLLVM_TARGETS_TO_BUILD=all
cmake --build llvm-project/build
cmake --install llvm-project/build

After that, they proceed to build with:

cmake -S . -B build -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_DIR=$(llvm-config --cmakedir) \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++
cmake --build build --config Release

Finallyand I leave you the following link where you can consult more about the details of the compilation as well as where you can find more information about the use of this compiler (manual, examples, functions, among other things).

The link is this.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.