Skip to content

Commit 2dea1cf

Browse files
authored
Write about Tier 2 and JIT in "what's new 3.13" (#114826)
(This will soon be superseded by Ken Jin's much more detailed version.)
1 parent 84e0e32 commit 2dea1cf

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

Doc/whatsnew/3.13.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ Important deprecations, removals or restrictions:
8181
* Python 3.13 and later have two years of full support,
8282
followed by three years of security fixes.
8383

84+
Interpreter improvements:
85+
86+
* A basic :ref:`JIT compiler <whatsnew313-jit-compiler>` was added.
87+
It is currently disabled by default (though we may turn it on later).
88+
Performance improvements are modest -- we expect to be improving this
89+
over the next few releases.
90+
8491

8592
New Features
8693
============
@@ -477,6 +484,46 @@ Optimizations
477484
FreeBSD and Solaris. See the ``subprocess`` section above for details.
478485
(Contributed by Jakub Kulik in :gh:`113117`.)
479486

487+
.. _whatsnew313-jit-compiler:
488+
489+
Experimental JIT Compiler
490+
=========================
491+
492+
When CPython is configured using the ``--enable-experimental-jit`` option,
493+
a just-in-time compiler is added which can speed up some Python programs.
494+
495+
The internal architecture is roughly as follows.
496+
497+
* We start with specialized *Tier 1 bytecode*.
498+
See :ref:`What's new in 3.11 <whatsnew311-pep659>` for details.
499+
500+
* When the Tier 1 bytecode gets hot enough, it gets translated
501+
to a new, purely internal *Tier 2 IR*, a.k.a. micro-ops ("uops").
502+
503+
* The Tier 2 IR uses the same stack-based VM as Tier 1, but the
504+
instruction format is better suited to translation to machine code.
505+
506+
* We have several optimization passes for Tier 2 IR, which are applied
507+
before it is interpreted or translated to machine code.
508+
509+
* There is a Tier 2 interpreter, but it is mostly intended for debugging
510+
the earlier stages of the optimization pipeline. If the JIT is not
511+
enabled, the Tier 2 interpreter can be invoked by passing Python the
512+
``-X uops`` option or by setting the ``PYTHON_UOPS`` environment
513+
variable to ``1``.
514+
515+
* When the ``--enable-experimental-jit`` option is used, the optimized
516+
Tier 2 IR is translated to machine code, which is then executed.
517+
This does not require additional runtime options.
518+
519+
* The machine code translation process uses an architecture called
520+
*copy-and-patch*. It has no runtime dependencies, but there is a new
521+
build-time dependency on LLVM.
522+
523+
(JIT by Brandt Bucher, inspired by a paper by Haoran Xu and Fredrik Kjolstad.
524+
Tier 2 IR by Mark Shannon and Guido van Rossum.
525+
Tier 2 optimizer by Ken Jin.)
526+
480527

481528
Deprecated
482529
==========

0 commit comments

Comments
 (0)