1 of 7

Tiers of Execution

Making CPython execute efficiently

2 of 7

Tiers

  1. Slowest tier. Minimal memory use and low startup time.
  2. Primary interpreter, the “adaptive, specializing interpreter”
  3. Small region, “lightweight” JIT
  4. Large region, “heavyweight” JIT

Each tier jumps to the next tier when code is sufficiently “hot”.

Nothing novel here. Just useful to have some terminology.

3 of 7

CPython today

Tier ~0.3

Compromise between memory use and speed.

Not well optimized for either.

4 of 7

Tier 0

Minimize start-up time and memory use, at expense of execution speed.

Support full set of features including sys.settrace

Should be able to execute from a .pyc file that it is mmapped and immutable.

Maybe 3.11, maybe later.

5 of 7

Tier 1

Adaptive, specializing interpreter.

Might not support all features, e.g. sys.settrace. Can fall back to Tier 0 if needed.

PEP 659

Planned for 3.11

6 of 7

Tiers 2 and 3

Entirely hypothetical at the moment.

“JIT” compilers.

Probably more like luajit than JVM, but I’m just guessing at this stage.

7 of 7

Optimization and Deoptimization

In the JVM, PyPy and other adaptive VMs, switching between tiers can be expensive.

We plan to make it cheap, by having the same in-memory data layout for all tiers.

This is desirable because:

  • We expect to have to switch between tiers often to support all of Python
  • We want to have an open-source development model, so each tier should be maintainable mostly independently.
  • It doesn’t cost that much in performance if the memory layout is designed carefully.