DeepMind open code S6, libraries with JIT compiler implementation for CPython

DeepMind, known for its developments in the field of artificial intelligence, has open-sourced the S6 project, which developed a JIT compiler for the Python language. The project is interesting because it is designed as an extension library that can be integrated with standard CPython, which provides full compatibility with CPython and does not require modification of the interpreter code. The project has been developing since 2019, but unfortunately it was curtailed and is no longer developing. Since the created developments may be useful for improving Python, it was decided to open the source texts. The JIT compiler code is written in C++, based on CPython 3.7. and is open under the Apache 2.0 license.

S6 for Python compares to the V8 engine for JavaScript in terms of tasks it solves. The library replaces the existing ceval.c bytecode interpreter handler with its own implementation that uses JIT compilation to speed up execution. S6 checks if the current function has already been compiled and, if so, executes the compiled code, and if not, runs the function in a bytecode interpretation mode similar to the CPython interpreter. Interpretation counts the number of executed instructions and calls associated with the function being processed. After reaching a certain milestone, the compilation process is initiated to speed up frequently executed code. Compilation is performed into the strongjit intermediate representation, which, after optimization, is converted into machine instructions of the target system using the asmjit library.

Depending on the nature of the load, under optimal conditions, S6 demonstrates an increase in the speed of test execution up to 9.5 times compared to the usual CPython. When running 100 iterations of the Richards test suite, there is an acceleration of 7 times, and when running the Raytrace test, which contains a large amount of mathematical calculations, it is 3-4.5 times faster.

Tasks that are difficult to optimize with S6 are projects that use the C API, such as NumPy, as well as operations related to the need to check the types of a large number of values. Poor performance is also observed for single calls of resource-intensive functions due to the use of S6's own non-optimized implementation of the Python interpreter (development has not reached the stage of interpreting mode optimization). For example, in the Unpack Sequence test, which unpacks large sets of arrays / tuples, with a single call, a slowdown of up to 5 times is observed, and with a cyclic call, the performance is 0.97 from CPython.

Source: opennet.ru

Add a comment