I rewrote the TLA+ model checker in pure no_std LLVM IR
What happens when you replace a 372 MB JVM model checker with 264 KB of hand-written LLVM IR and zero libc calls, and what chasing a 247× speedup on Paxos taught me about software layers.
A few days after finishing Cygnet, where I built a Forth virtual machine in raw LLVM IR, I caught myself staring at a very different piece of software: TLC, the official model checker for TLA+.
I have a soft spot for Leslie Lamport's work. When I wrote There Is No Now, I spent a lot of time thinking about how hard it is to reason about concurrent systems in your head. TLA+ is Lamport's answer to that problem. Instead of crossing your fingers and hoping your distributed protocol has no race conditions, you write down the rules of the system as math: what the starting state looks like, what transitions are allowed, and what invariants must always hold.
Then you hand that file to TLC. TLC walks every reachable state of your system, one step at a time, until it either proves no bad state exists or hands you the exact shortest sequence of steps that breaks your design. The classic warm-up example is the water jug puzzle from Die Hard with a Vengeance: you have a 5-gallon jug and a 3-gallon jug, and you tell TLC that the big jug can never hold 4 gallons. A fraction of a second later, TLC disagrees and prints the exact 7-step pouring sequence that solves the puzzle. Real teams use the exact same loop to find bugs in Paxos, Raft, and two-phase commit before writing production code.
What always bothered me a little is how heavy the tooling feels for something so clean conceptually. Official TLC is a 2.2 MB Java jar running on a 372 MB OpenJDK. Even checking a tiny 12-state clock spec takes over 600 milliseconds and 120 MB of memory just to wake up the JVM. I wanted to see what happens if you strip away the entire stack and rebuild TLC from scratch as a native, drop-in replacement written purely in no_std LLVM IR.
No C. No Rust. No standard library. Not a single libc symbol linked into the final binary. That project became IronTLA.
Talking straight to the kernel
Writing without a standard library changes how you think about a program right from line one. There is no malloc, no printf, no file API. On Apple Silicon, every read, write, file open, memory mapping, and process fork goes straight to the kernel through raw inline assembly syscalls. On top of that sits a small arena allocator, a string interner, buffered integer formatting, and a 64-bit hash set for state fingerprints.
One of my favorite moments happened ten minutes into building that runtime. I wrote a straightforward byte-copy loop, compiled it with optimizations on, checked the binary for external dependencies, and stared at _memcpy sitting there as an undefined symbol. LLVM had looked at my hand-written loop, recognized what it was doing, and helpfully replaced it with a call to libc. Telling the optimizer to keep its hands off my loops fixed it, and from that point on the undefined symbol count stayed at zero.
Honestly, I expected writing a full TLA+ parser and evaluator in LLVM IR to feel miserable. It turned out to be strangely calm. Once you commit to one clean memory layout for your AST nodes, values, and states, LLVM's assembler catches every type mismatch immediately. You lose high-level syntax sugar, sure, but you also lose every hidden allocation and surprise abstraction. You always know exactly how many bytes a state takes and where every pointer lives.
First contact with real TLA+ specs
To keep myself honest, I did not invent toy tests. I grabbed 12 real, unmodified specifications straight from the official tlaplus/Examples repository, ran Java TLC on all of them, and recorded the exact exit codes, generated state counts, distinct state counts, search depths, and error traces.
TLA+ has plenty of sharp corners when you actually try to match TLC faithfully. Comments can nest inside each other. Vertical conjunction and disjunction lists depend on column indentation rather than parentheses. Division and modulo are Euclidean, which disagrees with CPU integer division on negative numbers. And in TLA+, a range like 1..3 and a set like {1, 2, 3} are the exact same mathematical object, just like an empty sequence and an empty function. They have to compare equal and hash identically.
When all the modules finally linked together for the first time into a 106 KB binary, 7 out of 12 official specs passed on the spot, each finishing in a few milliseconds. A quick round of fixes for higher-order lambdas, infinite set membership checks, recursive local functions, and config overrides brought us to 11 out of 12 with exact state-for-state parity.
Then came the twelfth spec: SimplifiedFastPaxos.
How Paxos humbled me
At first, Paxos simply timed out. The reason was a single line in its config file declaring symmetry over the 3 values and 4 replicas. Without symmetry reduction, every permutation of replica names and value names looks like a different state, blowing up 1,207 distinct states into more than 170,000.
So I added symmetry reduction the obvious way: take every state the engine generates, apply all 144 permutations, sort and hash each permuted state, and keep the smallest fingerprint. It worked on the first try. Exact 1,207 distinct states, exact 13,290 generated states, exact depth 22. Twelve out of twelve passed.
Then I looked at the clock.
Java TLC finished Paxos in 1.65 seconds.
My hand-written LLVM IR binary took 7.87 seconds and burned 251 MB of memory.
There is something deeply motivating about losing by almost 5× to a JVM when you just wrote twenty thousand lines of LLVM assembly. That single number kicked off the most fun week of performance work I have done in years.
Thinking your way from 7,869 ms down to 31.8 ms
What struck me during the optimization passes is how rarely the biggest wins came from clever low-level tricks. Almost every major jump came from stepping back and realizing we were doing work that did not need to exist at all.
First, stop permuting things you have already seen. We were running all 144 permutations on all 13,290 generated states, nearly two million full state permutations. Because symmetry is a mathematical group, you can flip the problem around: check the raw state fingerprint first. If it is already in the seen set, you are done in one lookup with zero permutations. Only when you hit a genuinely new state (just 1,207 times) do you insert its whole 144-state orbit. Combining that with a resettable scratch arena so temporary states stopped piling up in RAM dropped Paxos from 7,869 ms to 557 ms, and memory fell from 251 MB down to 11.7 MB.
Second, stop sorting just to hash. Even 1,207 orbits were still allocating temporary sets and running heapsort only to throw the sorted arrays away the moment we had a 64-bit hash. Switching set and function hashing to a commutative sum meant element order no longer mattered at all. Suddenly we could hash any permuted state in place with zero allocations and zero sorting. Add load-time symbol resolution and a no_std multi-core BFS pool using raw process forks and shared memory, and Paxos dropped to 244 ms on one core and 124 ms on four.
Third, actually read the spec. This one made me laugh out loud. Opening Paxos.tla showed that four helper operators filtering the set of sent messages were being recomputed more than fifty times per state, even though the state never changes during a single expansion. Worse, the accept action looped over every combination of ballot, quorum, and value, checking a ballot-only guard and a quorum filter inside the innermost value loop. Caching pure operators per state and hoisting guards out to the loop level where their variables become bound cut the work in half again: 135 ms on one core, 81 ms on four.
Fourth, respect the shape of the math. The 144-element symmetry group is really two independent groups multiplied together: 24 replica permutations and 6 value permutations. Half the variables in Paxos only care about replicas, and one only cares about values. Factoring the symmetry group meant hashing each variable only over the permutations that actually affect it. And because Paxos only has 194 possible distinct messages in total, caching each message's permuted hash vector turned message-set symmetry hashing into a handful of NEON vector additions.
From there, the final polish brought everything together: streaming candidate states straight from a stack-allocated working buffer so duplicate states never even get cloned, compiling hot predicates and quantifiers into a tiny linear bytecode VM at load time, hash-consing immutable message records so equality becomes a single pointer compare, upgrading the hash set to a NEON 16-way SwissTable, and replacing spin loops in the worker pool with raw kernel futex waits.
When the dust settled, SimplifiedFastPaxos ran in 49.5 ms on one core (33.3× faster than Java TLC, using 5.53 MB of RAM vs Java's 441 MB) and 31.8 ms on four cores (40.1× faster than Java on four cores, and 247× faster than my first working build).
The numbers across all 12 specs
Across the full suite of 12 official specs (single-threaded, median of 3 runs), Java TLC takes 9.17 seconds total. IronTLA finishes all 12 in 128.4 milliseconds, with every single spec staying under 6 MB of RAM.
| Benchmark | Distinct States | Java TLC | IronTLA | Speedup | Java RAM | IronTLA RAM |
|---|---|---|---|---|---|---|
hour_clock | 12 | 657.3 ms | 6.88 ms | 95.6× | 118.1 MB | 1.80 MB |
cigarette_smokers | 6 | 684.8 ms | 6.05 ms | 113.2× | 125.0 MB | 1.88 MB |
asynch_interface | 12 | 637.8 ms | 5.74 ms | 111.2× | 119.0 MB | 1.83 MB |
die_hard | 14 | 645.2 ms | 6.45 ms | 100.1× | 119.6 MB | 1.84 MB |
tcommit | 34 | 643.4 ms | 5.98 ms | 107.6× | 123.5 MB | 1.84 MB |
tcommit_deadlock | 30 | 642.2 ms | 6.38 ms | 100.7× | 123.7 MB | 1.86 MB |
dining_philosophers | 58 | 736.8 ms | 7.15 ms | 103.1× | 139.8 MB | 1.84 MB |
missionaries_and_cannibals | 61 | 698.2 ms | 7.65 ms | 91.3× | 130.7 MB | 1.89 MB |
echo | 75 | 767.9 ms | 7.35 ms | 104.5× | 150.7 MB | 1.98 MB |
two_phase | 288 | 670.0 ms | 7.59 ms | 88.2× | 128.1 MB | 1.95 MB |
inner_fifo | 3,864 | 740.2 ms | 11.68 ms | 63.4× | 144.7 MB | 2.56 MB |
simplified_paxos (1w) | 1,207 | 1,649.9 ms | 49.53 ms | 33.3× | 440.7 MB | 5.53 MB |
simplified_paxos (4w) | 1,207 | 1,275.4 ms | 31.81 ms | 40.1× | 440.3 MB | 12.95 MB |
Why this feels worth doing
I do not expect anyone to start writing their day-job services in hand-crafted LLVM IR. That would be a terrible life choice. What I do find genuinely interesting is how much headroom is hiding underneath the layers we treat as fixed.
When a model checker finishes in 6 milliseconds instead of 650 milliseconds, it stops feeling like a separate batch step you only run before a design review. It starts feeling like a compiler check you can run on every save. And when the entire engine lives in pure LLVM IR, whole-program optimization stops being a linker flag you hope works and becomes the default: every module inlines straight into every other module, and porting the whole thing to Linux x86_64 and RISC-V mostly came down to writing a small syscall file per OS.
I also like the honesty of a 264 KB binary with zero external dependencies. Nothing is hidden in a runtime you did not ask for. If something is slow, it is because you wrote something slow, and if you fix the math, the stopwatch notices immediately.
Everything is open source at github.com/miolini/irontla (and listed under Projects). If you want to watch a tiny binary with zero libc symbols chew through Paxos in 31 milliseconds, clone it and run make && ./tests/verify.sh.