Facebook released the Cinder source code which is used by Instagram

Facebook unveiled recently through a post, releasing the source code of the Cinder project, which is a fork of the CPython branch and the main reference implementation of the Python programming language.

Cinder used in Facebook's production infrastructure to power Instagram and includes optimizations to improve performance. The code has been published to discuss the possibility of migrating ready-made optimizations to the mainstream of CPython and to aid other CPython performance improvement projects.

Facebook mentions that it will not support Cinder as a separate open source project and the code is presented in the form it is used in the enterprise infrastructure, without additional documentation.

Cinder is also not promoting itself as an alternative to CPython - the main development goal is to improve CPython itself.

Cinder's code is considered reasonably reliable and tested in production environments, but if problems are identified, they will need to be resolved on their own, as Facebook does not guarantee that it will respond to external error messages and pull requests.

At the same time, Facebook does not exclude constructive cooperation with the community and is ready to discuss ideas on how to make Cinder even faster or how to speed up the transfer of prepared changes to the main framework of CPython.

The main optimizations implemented in Cinder are:

  • Bytecode online caching: The essence of the method is to identify typical opcode execution situations that can be dynamically optimized and replace that opcode with faster specialized options.
  • Routine evaluation: For asynchronous function calls that are processed immediately, the result of those functions is directly substituted without creating a coroutine and without invoking an event loop. In the code used by Facebook, which it uses heavily, optimization leads to an acceleration of about 5%.
  • Selective compilation of JIT at the level of individual methods and functions: it is enabled by the "-X jit" option or the environment variable PYTHONJIT = 1 and allows many performance tests to be accelerated by 1,5 to 4 times.
    The list of functions for which JIT should be enabled can be determined based on the results of the profile. In the future, support for dynamic JIT compilation based on internal analysis of function call frequency is expected, but considering the specifics of launch processes on Instagram, JIT compilation is also suitable for Facebook in the initial stage.
    The JIT first converts Python's bytecode to a high-level intermediate representation (HIR), which is reasonably close to Python's bytecode, but is designed to use a record-based virtual machine rather than a record-based virtual machine. in stack, and also uses type information and additional details relevant to performance. The HIR is then converted to a Static Single Allocation (SSA) form and undergoes stages of optimization based on reference count and memory usage data. As a result, a low-level intermediate representation (LIR) is generated, which is close to assembly language.
  • Strict mode for modules:The functionality has three components: The StrictModule type. A static analyzer capable of determining that the execution of a module does not affect the code outside that module.
  • Static Python: is an experimental bytecode compiler that uses type annotations to generate bytecode that is specific to each type and runs faster through JIT compilation. In some tests, the combination of Static Python and JIT demonstrates up to 7x performance improvement over typical CPython. In many situations, the results are evaluated as if the MyPyC and Cython compilers were used.

Finally if you are interested in being able to obtain the Cinder code or learn more about it, you can consult the details in the following link.

The content of the article adheres to our principles of editorial ethics. To report an error click here!.

Be the first to comment

Leave a Comment

Your email address will not be published.



  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.