Pyjion#

Pyjion drop-in JIT compiler for CPython 3.10. Pyjion can make your Python code execute faster without any code changes.

Trying Pyjion#

Checkout the live Pyjion compiler and disassembler sandbox at trypyjion.com.

Prerequisites#

Installing Pyjion#

Pyjion is best installed from PyPi within a Python 3.10 virtual environment. There are binary wheels for macOS, Linux and Windows. Make sure you have updated pip before installing.

To install from PyPi, use pip to install from a virtual environment:

$ python -m pip install pyjion

Using Pyjion#

After following the installation steps, pyjion is a python module that you can import a Python 3.10 environment.

After importing pyjion, enable it by calling pyjion.enable() which sets a compilation threshold to 0 (the code only needs to be run once to be compiled by the JIT):

>>> import pyjion
>>> pyjion.enable()

Any Python code you define or import after enabling pyjion will be JIT compiled. You don’t need to execute functions in any special API, its completely transparent:

>>> def half(x):
...    return x/2
>>> half(2)
1.0

Pyjion will have compiled the half function into machine code on-the-fly and stored a cached version of that compiled function inside the function object. You can see some basic stats by running pyjion.info(f), where f is the function object:

>>> pyjion.info(half)
JitInfo(failed=False, compile_result=<CompilationResult.Success: 1>, compiled=True, optimizations=<OptimizationFlags.InlineFramePushPop|InlineDecref: 10>, pgc=1, run_count=1)

You can also execute Pyjion against any script or module:

pyjion my_script.py

Or, for an existing Python module:

pyjion -m calendar

For a full list of options, see the API Reference.