Skip to content

About

Experimental Free-Threaded (No-GIL) runtime and Tier 2 / Native JIT optimizations for CPython

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

 
 

Latest commit

 

History

134,046 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This is Python version 3.16.0 alpha 1+dev (Experimental No-GIL + JIT + @strict/@struct)

CPython build status on GitHub Actions CPython build status on Azure DevOps Python Discourse chat

This branch (experimental-nogil-jit) combines PEP 703 Free-Threading (--disable-gil), an enhanced Tier 2 Micro-Op Abstract Interpreter, a Native AArch64 Copy-and-Patch JIT, an Opt-In Sound Gradual Typing & Sealed Slot System (Lib/strict.py: @strict, @struct, strict_mode, strict_module), and a C-Level Work-Stealing Auto-Parallel Dispatch Engine.

  1. Zero-Indirection Free-Threaded Runtime ( --disable-gil ): Zero-indirection main-thread Thread-Local Bytecode (TLBC), worker TLBC specialization inheritance, unshared-local container fast paths (bypassing critical sections when ob_ref_shared == 0), and a unified 1- and 2-digit (<= 60-bit) PyLong per-thread freelist.
  2. Partial Escape Analysis / Scalar Replacement ( eliminate_non_escaping_struct_allocs ): Eliminates non-escaping @struct heap allocations inside hot loops by inlining __init__, forwarding field writes directly to downstream _LOAD_ATTR_SLOT consumers on the abstract stack, and removing _ALLOCATE_OBJECT / _CREATE_INIT_FRAME / _MAKE_HEAP_SAFE (6.21x faster than undecorated JIT on dataclass_inst at 4.57 ms, and 27.04x faster than unoptimized Tier 1).
  3. Perceus-Style Reference-Unique In-Place Reuse & FMA Fusion: Exploits PEP 703 biased reference counting (_Py_IsOwnedByCurrentThread(op) && ob_ref_local == 1 && ob_ref_shared == 0) to mutate PyFloatObject and 60-bit compact PyLongObject boxes in place across arithmetic chains, chained integer accumulators (c = c + b - a), slot updates (_STORE_ATTR_SLOT_FLOAT_INPLACE, _LOAD_ATTR_SLOT_NO_POP), hardware Fused Multiply-Add (_BINARY_OP_FMA_FLOAT_INPLACE), 60-bit compact-int bitwise/divmod (_BINARY_OP_BITWISE_INT), and mixed float-int arithmetic (_BINARY_OP_ARITH_FLOAT_INT).
  4. Basic Block Versioning & Fused Range-Iterator Induction ( hoist_loop_preheader_guards & _PyRangeIter_StepLocal ): Peels up to 256 micro-ops of the first loop iteration into a trace pre-header to prove steady-state local types and non-nullness (_LOAD_FAST -> _LOAD_FAST_BORROW), hoists invariant type/container/overflow guards, and fuses _GUARD_NOT_EXHAUSTED_RANGE + _ITER_NEXT_RANGE + _SWAP_FAST + _POP_TOP_INT into a single non-escaping uop (cutting float_loop to 6.89 ms, object_attr_churn to 8.50 ms / 6.03x, and int_loop to 31.24 ms / 1.24x).
  5. Opt-In Sound Gradual Typing ( @strict , @struct , strict_mode , strict_module ): Enforces primitive and container type annotations (int, float, str, bool, None, list, dict) and slot types in C via _Py_STRICT_SLOT_* flags on PyMemberDef and 64-bit _co_strict_sig bitmasks on PyCodeObject (zero wrapper frames), sealing classes with Py_TPFLAGS_IMMUTABLETYPE and seeding Tier 2 with guard-free static types while catching type violations across third-party boundaries via sys.monitoring.
# Configure and build free-threaded CPython with the native Copy-and-Patch JIT
mkdir -p build-nogil && cd build-nogil
../configure --disable-gil --enable-experimental-jit
make -j10

# Run the @strict/@struct unit suite and Tier 2 / JIT optimizer regression suite (341 tests)
./python.exe -m test test_strict test_capi.test_opt -j8

# Run the 11 paired workloads + 8 negative boundary enforcement tests
./python.exe ../Tools/benchmarks/bench_strict_duplication.py

*Parenthesized Tier 1 figures show unspecialized baseline before Tier 1 unshared-local and compact-int fast paths.

  • Copy-and-Patch JIT: H. Xu & F. Kjolstad, "Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode," OOPSLA 2021 (doi:10.1145/3485513).
  • Partial Escape Analysis: L. Stadler, T. Würthinger, & H. Mössenböck, "Partial Escape Analysis and Scalar Replacement for Java," CGO 2014 (doi:10.1145/2544137.2544157).
  • Tracing Allocation Removal: C. F. Bolz et al., "Allocation Removal by Partial Evaluation in a Tracing JIT," PEPM 2011 (doi:10.1145/1929501.1929508).
  • Basic Block Versioning: M. Chevalier-Boisvert & M. Feeley, "Simple and Effective Type Check Removal through Lazy Basic Block Versioning," ECOOP 2015 (doi:10.4230/LIPIcs.ECOOP.2015.101).
  • Reference-Unique In-Place Reuse: A. Reinking, N. Xie, L. de Moura, & D. Leijen, "Perceus: Garbage Free Reference Counting with Reuse," PLDI 2021 (doi:10.1145/3453483.3454032).
  • Biased Reference Counting & Free-Threading: J. Choi, T. Shull, & J. Torrellas, "Biased Reference Counting: Minimizing Atomic Operations in Garbage Collection," PACT 2018 (doi:10.1145/3243176.3243195); S. Gross, PEP 703.
  • Sound Gradual Typing & Static Python: A. Rastogi et al., "Safe & Efficient Gradual Typing for TypeScript," POPL 2015 (doi:10.1145/2676726.2676971); M. M. Vitousek et al., "Big Types in Little Runtime," POPL 2017 (doi:10.1145/3009837.3009849); Meta Engineering, Cinder Static Python.

Copyright © 2001 Python Software Foundation. All rights reserved.

See the end of this file for further copyright and license information.

For more complete instructions on contributing to CPython development, see the Developer Guide.

Installable Python kits, and information about using Python, are available at python.org.

On Unix, Linux, BSD, macOS, and Cygwin:

./configure
make
make test
sudo make install

This will install Python as python3.

You can pass many options to the configure script; run ./configure --help to find out more. On macOS case-insensitive file systems and on Cygwin, the executable is called python.exe; elsewhere it's just python.

Building a complete Python installation requires the use of various additional third-party libraries, depending on your build platform and configure options. Not all standard library modules are buildable or usable on all platforms. Refer to the Install dependencies section of the Developer Guide for current detailed information on dependencies for various Linux distributions and macOS.

On macOS, there are additional configure and build options related to macOS framework and universal builds. Refer to Mac/README.rst.

On Windows, see PCbuild/readme.txt.

To build Windows packages, see PC/layout/README.md.

If you wish, you can create a subdirectory and invoke configure from there. For example:

mkdir debug
cd debug
../configure --with-pydebug
make
make test

(This will fail if you also built at the top-level directory. You should do a make clean at the top-level first.)

To get an optimized build of Python, run configure --enable-optimizations before you run make. This sets the default make targets up to enable Profile Guided Optimization (PGO) and may be used to auto-enable Link Time Optimization (LTO) on some platforms. For more details, see the sections below.

PGO takes advantage of recent versions of the GCC or Clang compilers. If used, either via configure --enable-optimizations or by manually running make profile-opt regardless of configure flags, the optimized build process will perform the following steps:

The entire Python directory is cleaned of temporary files that may have resulted from a previous compilation.

An instrumented version of the interpreter is built, using suitable compiler flags for each flavor. Note that this is just an intermediary step. The binary resulting from this step is not good for real-life workloads as it has profiling instructions embedded inside.

After the instrumented interpreter is built, the Makefile will run a training workload. This is necessary in order to profile the interpreter's execution. Note also that any output, both stdout and stderr, that may appear at this step is suppressed.

The final step is to build the actual interpreter, using the information collected from the instrumented one. The end result will be a Python binary that is optimized; suitable for distribution or production installation.

Enabled via configure's --with-lto flag. LTO takes advantage of the ability of recent compiler toolchains to optimize across the otherwise arbitrary .o file boundary when building final executables or shared libraries for additional performance gains.

We have a comprehensive overview of the changes in the What's new in Python 3.16 document. For a more detailed change log, read Misc/NEWS, but a full accounting of changes can only be gleaned from the commit history.

If you want to install multiple versions of Python, see the section below entitled "Installing multiple versions".

Documentation for Python 3.16 is online, updated daily.

It can also be downloaded in many formats for faster access. The documentation is downloadable in HTML, EPUB, and reStructuredText formats; the latter version is primarily for documentation authors, translators, and people with special formatting requirements.

For information about building Python's documentation, refer to Doc/README.rst.

To test the interpreter, type make test in the top-level directory. The test set produces some output. You can generally ignore the messages about skipped tests due to optional features which can't be imported. If a message is printed about a failed test or a traceback or core dump is produced, something is wrong.

By default, tests are prevented from overusing resources like disk space and memory. To enable these tests, run make buildbottest.

If any tests fail, you can re-run the failing test(s) in verbose mode. For example, if test_os and test_gdb failed, you can run:

make test TESTOPTS="-v test_os test_gdb"

If the failure persists and appears to be a problem with Python rather than your environment, you can file a bug report and include relevant output from that command to show the issue.

See Running & Writing Tests for more on running tests.

On Unix and Mac systems if you intend to install multiple versions of Python using the same installation prefix (--prefix argument to the configure script) you must take care that your primary python executable is not overwritten by the installation of a different version. All files and directories installed using make altinstall contain the major and minor version and can thus live side-by-side. make install also creates ${prefix}/bin/python3 which refers to ${prefix}/bin/python3.X. If you intend to install multiple versions using the same prefix you must decide which version (if any) is your "primary" version. Install that version using make install. Install all other versions using make altinstall.

For example, if you want to install Python 2.7, 3.6, and 3.15 with 3.15 being the primary version, you would execute make install in your 3.15 build directory and make altinstall in the others.

See PEP 826 for Python 3.16 release details.

Copyright © 2001 Python Software Foundation. All rights reserved.

Copyright © 2000 BeOpen.com. All rights reserved.

Copyright © 1995-2001 Corporation for National Research Initiatives. All rights reserved.

Copyright © 1991-1995 Stichting Mathematisch Centrum. All rights reserved.

See the LICENSE for information on the history of this software, terms & conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.

This Python distribution contains no GNU General Public License (GPL) code, so it may be used in proprietary projects. There are interfaces to some GNU code but these are entirely optional.

All trademarks referenced herein are property of their respective holders.

About

Experimental Free-Threaded (No-GIL) runtime and Tier 2 / Native JIT optimizations for CPython

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages