Nuitka, a compiler that transforms Python into C for the sake of both performance gains and a more portable runtime, has reached its 0.6 release—a milestone that lays the groundwork for future performance gains. As Nuitka developer Kay Hayen put it, “Performance improvements are likely in every coming release.”
Nuitka 0.6 applies optimizations to Python’s
bool types (
true/false), so that code using them can be reduced to the most efficient possible C code. The
bool optimizations come as a prelude to similar optimizations for other variable types.
Nuitka, like Cython, compiles a Python program to C, and links the resulting executable against the Python runtime for maximum compatibility. Python versions 2.6, 2.7, and 3.3 through 3.7 are all supported, including constructions like
Python programs compiled with Nuitka can benefit from large performance boosts. Hayen claims a Nuitka-compiled version of the Pystone benchmark runs some 312 percent faster than a conventional CPython implementation.
But Hayen warns that the most significant performance improvements await the arrival of type inferencing in Nuitka, enabling the full translation of certain types of Python objects into native C versions.
Python’s dynamism makes many kinds of optimizations inherently difficult. Many Cython optimizations require a great deal of guidance and a specialized annotation syntax for the best results. The Nuitka project aims to provide the same sorts of optimizations without requiring the developer to annotate the code.
Another commonly used Python accelerator, PyPy, works by just-in-time compiling Python code to assembly. But PyPy works best for in-place optimization; it isn’t suited to compiling a Python app that is deployed in a stand-alone fashion. Nuitka generates stand-alone executables. One of its potential use cases is packaging up a Python app for third-party distribution.
Other improvements in Nuitka 0.6 include support on Windows for the Clang, Microsoft Visual C++, and Cygwin compilers, caching of object files for faster recompilation (again, on Windows), and auto-formatting of generated C code in
clang-format for readability.
Join the CIO Australia group on LinkedIn. The group is open to CIOs, IT Directors, COOs, CTOs and senior IT managers.