Shaw: Python 3.13 gets a JIT

Post Syndicated from corbet original https://lwn.net/Articles/957239/

Anthony Shaw describes
the new copy-and-patch JIT
that has been proposed for Python 3.13.

Copy-and-patch was selected because the compilation from bytecodes
to machine code is done as a set of “templates” that are then
stitched together and patched at runtime with the correct
values. This means that your average Python user isn’t running this
complex JIT compiler architecture inside their Python
runtime. Python writing it’s own IL and JIT would also be
unreasonable since so many are available off-the-shelf like LLVMs
and ryuJIT. But a full-JIT would require those being bundled with
Python and all the added overheads. A copy-and-patch JIT only
requires the LLVM JIT tools be installed on the machine where
CPython is compiled from source, and for most people that means the
machines of the CI that builds and packages CPython for python.org.