Automatically cross compiles .py files to .so (or .pyd) using Cython and import hooks.
How to use:
import pythonjit pythonjit.enable()
And imports will automatically be cythonized.
For more performance benefits, use the decorators provided by cython to statically type variables and return types. The relevant decorators are:
- @cython.cfunc (declares cdef function)
- @cython.ccall (declares cpdef function)
- @cython.returns (declare return type)
- @cython.locals (declare local variable types)
- @cython.cclass (declare cdef class)
- @cython.inline (equivalent to C inline keyword)
- @cython.final (makes subclassing impossible, enabling optimizations)
Types are also part of the cython module:
For more information on cython types and decorators, see the cython docs
Bugs in your code and compilation time
Cython is more stringent than the python interpreter when it comes to catching errors in code. E.g. It will complain about NameErrors that occur in unreachable code, which the python interpreter will not do. A larger/complex project may have issues to fix before Cython can compile it.
Cross compilation can take some time, especially for larger projects. A caching mechanism is used to compensate for this, so the first run will be slower than future runs.
cythonmust be installed
gccmust be available (Windows users should install MinGW to gain access to
__file__may not be available in compiled modules - seehere for a workaround
- Supports python 2 and 3, but the default version is set to 2.
Read the Docs
More documentation can be found on readthedocs