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

https://news.ycombinator.com/rss Hits: 8
Summary

Python 3.15’s Ultra-Low Overhead Interpreter Profiling Mode 1 July 2026 Python’s 3.15 JIT shows modest speedups over the interpreter. Key to that is a (to the best of my knowledge), new form of interpreter profiling that was developed for recording execution through the interpreter for JIT compilation. This form of profiling does not introduce much overhead over the interpreter as well, allowing for low-overhead JIT compilation. I wouldn’t be surprised if someone actually already came up with this before, but as far as I could find, it’s not documented anywhere. Brief Background In an earlier post, I explained trace recording in the CPython 3.15 JIT. The key idea is that we record an instruction stream through actual program execution, until we hit some terminating condition, then we send that for JIT compilation. Naturally, this requires an instrumented/profiled interpreter. Profiling an Interpreter There are normally two avenues of profiling an interpreter: Have two bespoke interpreters (one for execution and one just for profiling). Implement a “profiling mode”. Approach 1: Two Interpreters The normal interpreter will have points calling into the profiling interpreter, and a way for the profiling interpreter to return into the normal interpreter. This allows switching back and forth between interpreters. This was the initial implementation of trace recording in CPython. I found it to be alright for the tail-calling interpreter but too slow for the computed goto interpreter (roughly a 6% slowdown on pyperformance!). I suspect the main reason was that we doubled the size of the actual interpreter implemented in C effectively for computed gotos, as that feature is function-scoped. Doubling the size of your C binary is usually not good for performance for various reasons. Approach 2: Profiling Mode The other common way to implement a profiling interpreter is to have a “profiling mode” which conditions some profiling logic on a boolean, say bool profile. While this mi...

First seen: 2026-07-21 12:26

Last seen: 2026-07-21 19:32