Fundamentals 6 min read

How CPython’s New JIT Will Boost Python 3.13 Performance

The upcoming CPython 3.13 release will optionally include a JIT compiler built on LLVM, offering modest speed gains of 2%‑9% today and promising larger improvements in future versions through advanced optimization techniques.

21CTO
21CTO
21CTO
How CPython’s New JIT Will Boost Python 3.13 Performance
Read: CPython core will include JIT technology.

Reliable sources indicate that the next CPython version will contain a Just‑In‑Time (JIT) compiler. Early user tests show direct runtime speed improvements and a promising outlook for further optimizations. The new JIT will be optional in Python 3.13 and can be enabled by building CPython with the -enable-experimental-jit flag.

Core developer Brandt Bucher submitted a pull request with the initial code last month. Python 3.13 is scheduled for release in October 2024.

JIT compilers are already used by other high‑level languages such as Java, PHP, and C#. They compile interpreted code to native machine code at runtime, delivering large speed gains without requiring developers to take extra steps.

The JIT’s goals include broad OS support, low implementation complexity, simple deployment, and no additional runtime dependencies for end‑users.

Bucher explained in a CPython Core Developer Sprint talk that the JIT is implemented using a “copy‑and‑patch compilation” technique proposed by Stanford researchers Haoran Xu and Fredrik Kjolstad in 2021. The idea is to splice together code fragments from a large binary implementation variant library, treating those fragments as templates that are patched with missing values during code generation.

Compared with other JIT techniques, the copy‑and‑patch approach is easier to implement for CPython while still producing high‑quality code.

The JIT is built on the LLVM ecosystem, using clang with -O3 for maximum performance. It exists only when building the CPython runtime, not at deployment time. Supported operating systems include Windows, macOS (x86 and ARM64), and Linux (x86 and ARM64).

How much faster is CPython with the new JIT compiler?

Bucher commented on GitHub: “At the moment it is 2%‑9% faster than the tier‑2 interpreter, depending on the platform (benchmarks vary from –13% to +47%).”

In short, we should not expect dramatic speed boosts yet, but the incremental gains are commendable and complement other Python acceleration efforts.

Future migrations to the JIT will aim for better performance. Bucher described possible optimizations such as using the ghccc calling convention for more efficient tail calls, reducing push/pop and register shuffling at function entry and exit. Each adds complexity and may become a separate review project, but prototypes have shown feasibility.

This work builds on CPython 3.11, which introduced a specialized adaptive interpreter, and 3.12, which uses a domain‑specific language to generate the interpreter, allowing build‑time modifications and analysis.

The effort is part of the long‑term Python acceleration roadmap.

Author: Luo Yi Source: 21CTO Comprehensive

Related reading:

Ruby 3.2.0 released with WebAssembly compiler, production‑ready YJIT optimizations, and faster regex engine

Microsoft launches powerful AIGC virtual machine, expands Azure OpenAI; Linux disables RNG on all AMD fTPM

phpy: PHP‑Python interop library brings Python ecosystem to PHP, enabling AI development in PHP

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

performancePythonJITLLVMinterpreterCPython
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.