Hasty Briefsbeta

Bilingual

Python 3.15's Ultra-Low Overhead Interpreter Profiling Mode – Ken Jin's Blog

14 hours ago
  • #Interpreter Profiling
  • #Low-Overhead Tracing
  • #Python JIT
  • The CPython 3.15 JIT introduces a novel low-overhead profiling method for trace recording without significantly slowing down the interpreter.
  • Instead of using two separate interpreters or a boolean profiling mode, the new approach uses two dispatch tables: one for normal execution and one for profiling.
  • Swapping dispatch tables at runtime enables switching between modes without branching, minimizing performance overhead.
  • In profiling mode, all instructions in the second dispatch table map to a single recording instruction that handles profiling and dispatches to the normal interpreter.
  • Benchmark results show profiling overhead is only about 4.5x slower than the interpreter alone, a substantial improvement over systems like PyPy, which can be 900x-1000x slower.
  • This profiling technique is not limited to trace recording; it can be adapted for low-overhead runtime profiling or type profiling in interpreters.
  • Despite its elegance, the author questions whether the complexity of this system is justified, preferring simpler solutions.