Pyjion, a just-in-time (JIT) compilation system for Python that compiles to the .NET 6 runtime, is now available in a 1.0 version.
Pronounced “pigeon,” and developed by Python Software Foundation fellow and Microsoft fellow Anthony Shaw (as a fork from its original Microsoft codebase), Pyjion is not a standalone runtime like PyPy, but an installable library that runs under Python 3.10. Once installed, Pyjion can be used in a program simply by importing the Pyjion library and enabling it. Everything that runs after that statement is JIT-compiled.
Pyjion works by compiling Python virtual machine opcodes into assembly language by way of the .NET EE compiler. Benchmarks conducted by the project’s maintainers show that Pyjion is about two to three times faster than regular Python for real-world work. Some of the optimizations allow speedups of up to 10 times. Regular arithmetic, always a good candidate for being JIT-optimized, can be an order of magnitude faster.
Some Python features are not implemented yet in Pyjion, such as
with blocks and
await, but both are on the roadmap. Pyjion does include a middleware layer to allow WSGI applications to run under Pyjion. A long-running application like a web app is a good candidate for JIT acceleration.
It has historically been difficult to make Python faster for a whole slew of reasons. Most methods for speeding up Python still rely on the Python C API for compatibility, so performance can end up being limited by that. Cython, the project that compiles Python into C, achieves its best performance with code that has no reliance on the Python C API at all.
Although Pyjion still relies on the Python C API, its current and future-planned optimizations (e.g., optimizing access to array types) show that its developers are thinking about how to deal with that.
Copyright © 2021 IDG Communications, Inc.