How to write a JIT compiler in 30 minutes
summary
Claims a working x86_64 JIT for a float-only subset of Python is written from scratch during the demo and actually runs. Uses an assembly encoder library, allocates executable memory with mmap + ctypes.CFUNCTYPE, and emits machine bytes; parses Python with ast visitor + stack evaluation, implements a trivial register allocator (one register per variable), supports constants, names, binary ops, assignments, comparisons, if/while and a @compiled decorator. The produced JIT sometimes needs debugging but runs a Pi-digit benchmark several times faster than CPython.
AI-written summary · about
chapters (13)
- 0:00Introduction and scope
- 1:04Understanding machine code
- 2:26Executing code from Python
- 4:11Creating a JIT test framework
- 5:51Implementing register allocator
- 8:50AST parsing and code generation
- 16:53Handling constants and returns
- 20:23Compiling function arguments
- 22:19Binary operations and assignment
- 26:43Control flow with If statements
- 32:40Function decorator implementation
- 33:58Benchmarking and conclusion
- 36:11Q&A session
related talks
29mBuilding a JIT compiler for CPython
29mWhat they don't tell you about building a JIT compiler for CPython
17mInside a PyPy JIT: is that even legal?
32mProfiling at the speed of light
45mTwo-level Just-in-Time Compilation with One Interpreter and One Engine
44mBuild Your Own VM with JIT Compilation for Dummies
24mHow two undergrads from the other side of the planet are speeding up...
22mPyPy and the future of the Python ecosystem
