Programming Languages
Automatically Adding JIT Compilation to Existing Language Runtimes
A new technology called yk can retrofit just-in-time compilers into existing language implementations with minimal code changes, achieving significant speedups on dynamically typed languages.
InfoQ
Building fast just-in-time (JIT) compilers for programming languages is notoriously difficult and expensive. Most attempts end up abandoned, incompatible with existing code, or unable to keep pace with language evolution. Laurence Tratt and collaborators have developed yk, a technology that takes a different approach: automatically retrofitting JIT compilation into existing language runtimes without requiring massive rewrites.
The Performance Promise#
The potential gains are substantial. In demonstrations, yk applied to Lua accelerated a Mandelbrot benchmark from 3.2 seconds to 0.8 seconds—a 4× speedup. More broadly, across a range of Lua programs, yk typically achieves around 2× improvement. Early experiments with MicroPython show similarly promising 2× gains. Remarkably, the implementation required only 400 added lines and 50 modified lines in the Lua VM—less than 5% of the codebase.
Why JIT Compilers Are So Hard to Build#
The fundamental problem is that hand-crafted JIT systems are extremely costly and fragile. The Java HotSpot VM required thousands of person-years of effort. V8 (Chrome's JavaScript engine) was built by a team of 50 engineers. When you finally get a JIT compiler working, you often face three killer problems:
- Incompatibility: New implementations rarely run all existing code without issues, causing users to abandon them.
- Ecosystem friction: If modules and extensions don't work, adoption stalls.
- Language evolution lag: When language specifications change, embedded assumptions in the JIT break down. LuaJIT, for instance, remains stuck on an older Lua version and cannot easily track the current language.
Two prior approaches—RPython (meta-tracing) and Truffle (partial evaluation)—showed these problems can be solved by writing a fresh interpreter in a host language (Python or Java). Both achieved impressive performance. Yet both struggle with the same evolution and compatibility issues that plague other JIT projects.
A Different Approach: Build on the Standard Implementation#
Tratt's insight is deceptively simple: the de facto standard implementations—CPython for Python, MRI/CRuby for Ruby, the Lua VM for Lua—are the real source of truth. These C interpreters, not language specifications, define what "correct" means. Users expect their programs to behave exactly as they do on the standard implementation.
