Multi-level Quickening: The Key to Interpreter Performance
First-level Quickening: Type Feedback
Multi-level Quickening: The Key to Interpreter Performance
Second-level Quickening: Type Propagation
Multi-level Quickening: The Key to Interpreter Performance
Optimized Instruction Derivatives
i.e. Make instructions more optimized for machine data types
●Mapping Integer Numbers
○uint64_t ? int64_t ? int32_t
●Mapping Floating Point Number
●Mapping Complex Numbers.
Multi-level Quickening: The Key to Interpreter Performance
Performance
Results
Quickening & Specialization in Reality
Python 3.11
●Specialization clicks in after 8
executions.
●25% faster than Python 3.10.
Python 3.12
●Specialization clicks in after 2
executions.
●Special more new bytecodes.
Table of contents
Copy-and-patch JIT Compilation
Motivated by Copy-and-Patch Compilation: A fast compilation
algorithm for high-level languages and bytecode
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
What’s JIT Compilation
●Just in time Compilation, only compile on demand when running for the 1st time.
●In contrast, compiled languages is using “Ahead of time”, compile before being used.
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
Interpreting
Parse into
Bytecode
Execution
Copy-and-Patch JIT Compilation
Copy
Bytecode
Execution
Patch
arguments
Running a
function
several
times
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
Normal Interpreting
Each time we run a function, CPython parse it into bytecodes, in a loop:
>>> def get_one():
... a = 1
... return a
Copy-and-Patch Compilation:
A fast compilation algorithm for high-level languages and bytecode
Copy-and-Patch JIT
>>> def get_one():
... a = 1
... return a
A function with the same
functionality, but written
in a lower language, e.g. C
or Assembly.
Table of contents
Caveat
Copy Instruction is kind of code generation, may expose security concerns.
iOS prohibits such dynamic code generation.
Copy-and-Patch Compilation in Reality
Table of contents
A basic JIT compiler will
be added in Python 3.13
(disabled in beta at the moment)
Take Away
●Upgrade to the latest Python version (official releases)
○Save energy
○Save money
○Save environment
References
●Implementation plan for speeding up CPython
●Multi-Level Quickening: Ten Years Later
●Copy-and-Patch Compilation: A fast compilation algorithm for high-level languages and bytecode
●Python 3.13 gets a JIT