Brandt Bucher – A JIT Compiler for CPython

encukou1 HN recommenders · 2023–2024
14K views · talk · dated · Uploaded 2023-11-15

Brandt Bucher presents his prototype JIT compiler for CPython at the 2023 Core Developer Sprint. He explains the copy-and-patch approach, the implementation and its performance.

It is the go-to explanation of how CPython's JIT works and why its design is so simple.

Watch on YouTube

3 comments from Hacker News

@acqq2023 · in “What's up Python? Epic CPython commit, Django 5 and 2FA for PyPI”

"Only 35% slower overall than LuaJIT" as per video from a month ago. No idea which kind of tests are these "overall" though. [VIDEO] Slides (pg. 31 performance): [LINK]

@vanderZwan2024 · in “Python 3.13 Gets a JIT”

You're right, and in this case "foundational work" even undersells how minimal this work really is compared to the results it already gets. I recommend that people watch Brandt Bucher's "A JIT Compiler for CPython" from last year's CPython Core Developer Sprint[0]. It gives a good impression of the current implementation and its limitations, and some hints at what may or may not work out. It also indirectly gives a glimpse into the process of getting this into Python through the exchanges during the Q&A discussion. One thing to especially highlight is that this copy-and-patch has a much, much lower implementation complexity for the maintainers, as a lot of the heavy lifting is offloaded to LLVM. Case in point: as of the talk this was all just Brandt Bucher's work. The implementation at the time was ~700 lines of "complex" Python, ~100 lines of "complex" C, plus of course the LLVM dependency. This produces ~3000 lines of "simple" generated C, requires an additional ~300 lines of "simple" hand-written C to come together, and no further dependencies (so no LLVM necessary to run the JIT. Also "complex" and "simple" qualifiers are Bucher's terms, not mine). Another thing to note is that these initial performance improvements are just from getting this first version of the copy-and-patch JIT to work at all , without really doing any further fine-tuning or optimization. This may have changed a bit in the months since, but the situation is probably still comparable. So if one person

Strongly recommendsView on HN
@Qem2024 · in “Copy-and-Patch: Fast compilation for high-level languages and bytecode (2020)”

Yes. This is the algorithm chosen for the CPython JIT under development, scheduled for inclusion from 3.13 onwards. See [VIDEO]