Talks to Watch

Brandt Bucher – A JIT Compiler for CPython

14K views · Nov 15, 2023 · 47:51 · 1 HN recommender · 3 mentions · discussed 2023–2024

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.

Why Hacker News points people here: It is the go-to explanation of how CPython's JIT works and why its design is so simple.

“I recommend that people watch Brandt Bucher's "A JIT Compiler for CPython" from last year's CPython Core Developer Sprint[0].”HN comment, 2024

What Hacker News said 3

Strongly recommendsvanderZwanJan 2024

“I recommend that people watch Brandt Bucher's "A JIT Compiler for CPython" from last year's CPython Core Developer Sprint[0].”

Shows current CPython JIT implementation, limitations, and low complexity

Full comment

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

Cites itacqqDec 2023

“Only 35% slower overall than LuaJIT" as per video from a month ago.”

Cites JIT performance versus LuaJIT from the talk

Full comment

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

in “What's up Python? Epic CPython commit, Django 5 and 2FA for PyPI” · view on HN
Cites itQemJun 2024

“This is the algorithm chosen for the CPython JIT under development”

Copy-and-patch chosen for CPython JIT

Full comment

Yes. This is the algorithm chosen for the CPython JIT under development, scheduled for inclusion from 3.13 onwards. See this video

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