DeepMind released the source code for S6, a JIT compiler for Python

s6-deepmind

S6, is a standalone JIT compiler library for CPython

deepmind, known for its developments in the field of artificial intelligence, recently announced that has made the decision to release the source code of the S6 project, which is he developed from a JIT compiler for the Python language.

The project is interesting because is designed as an extension library which can be integrated with standard CPython, which provides full CPython compatibility and does not require modification of the interpreter code. The project has been in development since 2019, but has unfortunately been scaled back and is no longer in development.

S6 was a project started within DeepMind in 2019 to speed up CPython with just-in-time ("JIT") compilation. These functions would be provided as a normal Python library and no changes to the CPython interpreter would be required. S6 intended to do for Python what V8 did for Javascript (the name is an homage to V8). The work was based on CPython version 3.7. Depending on the workload, we saw speedups of up to 9.5x in common benchmarks.

The main reason why it was decided to release the source code, one of them and as already mentioned was that the project stopped having support, another of the main reasons was given that based on the developments created, these can still be useful for improve python.

We have stopped working on S6 internally. As such, this repository has been archived and we are not accepting pull requests or issues. We open sourced and provided a design overview below to stimulate conversations within the Python community and inspire future work to improve Python.

Regarding the operation of S6, we should mention that S6 for Python compares to V8 engine for JavaScript in terms of tasks it solves. The library replaces the existing ceval.c bytecode interpreter driver 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, executes the function in a bytecode interpretation mode similar to the CPython interpreter. The interpretation counts the number of executed statements and calls associated with the function being processed.

After reaching a certain milestone, the build process is started to speed up the code which runs frequently. Compilation is performed on the strongjit intermediate representation, which, after optimization, is converted to target system machine instructions using the asmjit library.

Depending on the nature of the load, under optimal conditions, S6 demonstrates an increase in test execution speed of up to 9,5 times compared to regular CPython.

When 100 iterations are executed from the Richards test suite, there is an acceleration of 7 times, and when running the Raytrace test, which contains a lot of math, it's 3 to 4,5 times faster.

Tasks that are difficult to optimize with S6 are the 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 seen for single function calls which consume a lot of resources due to the use of the unoptimized implementation of the S6 Python interpreter (development has not reached the stage of interpret mode optimization).

For example, in the Unpack Sequence test, which unpacks large sets of arrays/tuples, a single call shows a slowdown of up to 5 times, and a cyclic call yields 0,97 from CPython.

Finally for those interested in knowing more about it, you should know that the JIT compiler code is written in C++ and is currently based on CPython 3.7, in addition to the fact that the source code is already open under the Apache 2.0 license and can be consulted from the link below.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.