Rung
A programming language I built five ways, to measure what really makes code run fast.
Personal project · Sep to Oct 2026
Results
- 38.84×fib, JIT vs. tree-walkermedian per call, Apple M1 Pro
- 22.38×loop_sum, JIT vs. tree-walkerthe JIT compiles functions in fib and loop_sum
- 4.54×fib, JIT vs. register VM13.37 ms to 2.94 ms, same session
- 1.30× to 4.99×Stack VM vs. tree-walkeracross six benchmarks
Rung highlights
- 01Tree-walker1.00×base
- 02Stack VM3.80×3.80×
- 03+ computed goto4.53×1.19×
- 04+ NaN-boxing4.06×▼ 0.90×
- 05Register VM5.71×1.41×
- 06+ superinstructions5.76×1.01×
- 07+ inline caches8.41×1.46×
- 08+ constant folding8.55×1.02×
- 09+ ARM64 JIT38.84×4.54×
One language, five engines.
32-bit ints, floats, strings, arrays, closures. Small enough to build five times: tree-walker, stack VM, register VM, baseline ARM64 JIT, background JIT. All five must print byte-identical output.
Bytecode beats walking the tree.
The stack VM runs 1.30× to 4.99× faster than the tree-walker across six benchmarks. Computed-goto dispatch adds up to another 1.81× on sieve.
Fewer instructions, same work.
The register VM does sieve's work in a third of the stack VM's instructions. Superinstructions cut strcat's dispatched instructions by 36.5%, and inline caching for globals gave fib 1.46×.
A rung that measured slower.
NaN-boxing halved value size, 16 to 8 bytes, and heap allocation, about 192 MB to 96 MB per process. Sieve still ran at 0.63× the rung below. I kept the result in the table.
Native code, with an exit.
The JIT hand-encodes ARM64, checked byte for byte against LLVM's assembler. When a type check fails mid-function it bails out and resumes in the VM. fib runs 38.84× faster than the tree-walker and 4.54× faster than the register VM.
Why
How much is each classic interpreter optimization actually worth? Every explanation of how Python, Lua or JavaScript get fast lists the same techniques, so I built each one myself and measured it. One small language, built five ways: a tree-walker, a stack VM, a register VM, a baseline ARM64 JIT and a JIT that compiles on a background thread. All five share one runtime and garbage collector, and every engine must print byte-identical output. The benchmark ladder adds one change per rung and measures only what that change buys.
What I built
- Hand-wrote the ARM64 instruction encoder, verified byte for byte against LLVM's assembler, with no codegen library. When a type check fails, the JIT bails out mid-function and resumes in the VM, even four calls deep.
- Built a background compiler that hands code off with release/acquire ordering, checked under TSan. On the warmup benchmark it cut p99 from 0.89 ms to 0.28 ms.
- Tested it in five layers: a conformance suite on every engine, ASan, UBSan and TSan builds, a libFuzzer harness, and CI on macOS ARM64, Linux ARM64 and Linux x86-64, including a 60 s fuzz job.
- Found a JIT crash in about 5% of Linux ARM64 runs by looping the test 300 to 600 times in CI. UBSan reads 8 bytes before an indirect-call target; 16 zero bytes before the code fixed it.
Built with
C++20, ARM64, CMake, Ninja, Clang, libFuzzer, ASan / UBSan / TSan, Docker, GitHub Actions