The Compiler Picks the Machine

We owed Bend's community an answer. We rented quiet boxes, measured every cell three times, and let the losses — including the unstable ones — stay on the page.

· 12 min read
BenchmarksCompiler InternalsParallelism

TL;DR

Bend’s community told us they were fast. So we measured — the whole Osprey compute-kernel suite, 22 integer-recursion kernels, on dedicated-vCPU Hetzner CCX43 boxes (16 vCPUs, no noisy neighbors), inside a pinned Docker rig, every binary verified against its integer oracle before timing, hyperfine -N --warmup 3 --min-runs 10 per cell. We ran the board three times in three datacenters — nbg1, hel1, fsn1 — because the first two runs disagreed with each other.

The result, identical on all three boards: Koru is ahead on 20 of 22 cells — and the two losses are not always the same two. tak loses everywhere, decisively. The second loss rotates: mutual on two boards, josephus on the third — both marginal cells close enough to flip sign between runs. An earlier draft of this post said “21 of 22” because it spliced one board’s table with another board’s mutual number. That 21/22 never existed on any single run, and it doesn’t appear here again.

The board, then the two machines: 20 of 22 on every board we rented, tak conceded by name, and the fork/join-versus-worklist choice the compiler makes from the shape of the recursion.

The board

All numbers are mean wall-clock milliseconds from the fsn1 board — the newest compiler, the fullest toolchain field, and the run whose teardown receipts we hold (artifact SHA-256 30d7678a…). Koru’s strongest arm vs Bend’s strongest arm, per cell:

kernelKoru bestBend bestverdict
powmod6.5 (par)429.6 (par)Koru −98%
factorial4.5 (par)320.9 (par)Koru −99%
binarytrees3.0 (seq)201.3 (seq)Koru −98%
coprime9.4 (par)71.2 (par)Koru −87%
gcdsum9.7 (par)65.4 (par)Koru −85%
nestedloop5.5 (par)35.9 (par)Koru −85%
digitsum4.2 (par)40.5 (par)Koru −90%
collatz5.8 (par)28.7 (par)Koru −80%
isqrt4.5 (par)39.5 (par)Koru −89%
primes6.6 (par)29.6 (par)Koru −78%
exprtree7.3 (seq)30.0 (seq)Koru −76%
hanoi48.4 (seq)160.6 (seq)Koru −70%
textstats4.4 (seq)14.0 (par)Koru −68%
ackermann38.4 (seq)117.8 (seq)Koru −67%
wordfreq2.0 (fold)3.4 (seq)Koru −42%
listops1.7 (seq)2.8 (seq)Koru −39%
coins16.2 (par)19.9 (par)Koru −18%
pascal43.4 (seq)47.2 (par)Koru −8%
fib11.2 (par)12.0 (par)Koru −7%
josephus40.1 (seq)42.3 (seq)Koru −5%
mutual5.8 (par) ±12.94.3 (seq)Bend −27%
tak45.0 (seq)23.3 (par)Bend −48%

And the full column set — C, GCC -O3, Clang, Rust — is in results/latest.json, committed next to the harness.

Aggregated, the table says one thing: taking Koru’s best arm against Bend’s best arm and averaging the per-kernel ratio geometrically over all 22 cells gives 4.2× on fsn1 — 3.9× on nbg1 and 4.0× on hel1. The big cells are genuinely big (factorial 71×, powmod 66×); what holds the aggregate near four rather than twenty is the run of near-parity cells — fib 1.07×, josephus 1.05×, coins 1.23×, pascal 1.09×. That is also the number to quote when someone asks “how much faster”: the median cell flatters us more, and the mean is hostage to factorial.

The loss that stays, and the cell that won’t sit still

tak is the stable loss. It loses on all three boards by roughly the same margin — Koru 44.4–47.5 ms against Bend-par’s 23.2–23.3 — and the reason is architectural, not noise. tak is self-recursive but three-way permuted: three calls with rotated arguments feeding a fourth. Bend’s compiler defunctionalizes everything into worklist states on per-worker rings, so its machine steals at reduction granularity — every step is a stealable work item. Ours works at call granularity, and on an exponential permuted tree the bookkeeping costs more than the parallelism earns.

We know this precisely because we measured the failure twice. On the hel1 board — compiler commit 48d4818cc, which had just fixed dead [parallel] marks — tak-par measured 74.1 ms, 56% worse than its own sequential arm. Fork/join on this shape is a loss, full stop. The response was a decline rule: shapes the compiler can’t classify (symmetric → fork/join, provably-asymmetric → worklist) fall back to synchronous calls rather than gamble. That rule is committed as e41988955 — and the fsn1 board, which ran that exact commit, measured tak-par at 85.4 ms against sequential 45.0. The decline rule did not produce the seq-floor the commit message promised. We’re reporting that here because the alternative — quoting the design instead of the measurement — is how this post originally went wrong. The regression fix is a bug, currently open, and tak stays red until a board says otherwise.

mutual is the cell that won’t sit still. Bend’s port folds is-even/is-odd into a single self-recursive eo(n, flag) tor — their language has no forward references, so mutual recursion must be encoded as a flag-carrying self-call. Writing the same fold in Koru — semantics-identical, oracle unchanged — measured 3.7 ± 0.6 ms against Bend’s 4.3 on hel1: a real win, tight variance. On nbg1 the same comparison measured 6.0 ± 1.2 — a loss. On fsn1, 5.8 ± 12.9 — a loss, with a standard deviation more than twice the mean, which means the measurement itself is bimodal garbage that no verdict should rest on. The transform is real; the win is unreproduced. It doesn’t count, and it isn’t counted in the 20.

josephus is the third marginal cell — Koru 40.1 vs Bend 42.3 on fsn1 (a win), 43.3 vs 40.1 on hel1 (a loss), 42.2 vs 45.9 on nbg1 (a win). Two measurements inside each other’s error bars. It counts as a win on this board and a loss on that one, and the honest thing is to say the cell is a coin flip, not to pick the run that flatters us.

What the wins are made of

The consistent part of the board — the part that reproduces in all three datacenters — is the parallel machinery. Two mechanisms, both committed:

  1. Economic fork/join. Every [parallel] call used to pay join bookkeeping even when it never spawned. Now a per-callsite flag gates the drain, the shared task atomic is probed in batches, and self-recursive calls fork only while an integer input field clears a work-size floor. fib-par sits at 11.2 vs Bend-par’s 12.0 on all three boards — a photo-finish that goes our way every time, by less than a millisecond.

  2. A stealable worklist for the provably-pure, provably-skewed slice. When the compiler proves a tor is self-recursive, pure, and asymmetric — self-calls that shrink different parameters at different rates, like coins’ amount-c vs kind-1 — it lowers the recursion onto a per-event deque: calls push items, workers steal, joins wait on a done count. No spawn-per-call, no depth cap. coins-par measures 16.2–16.4 ms on all three boards against Bend-par’s 19.3–19.9 — the most stable parallel win on the board.

The asymmetry gate is the part I’m proudest of: the compiler reads the shape of the recursion — fib’s n-1/n-2 are symmetric so it keeps fork/join; coins’ calls are asymmetric so it picks the worklist. Same surface syntax, different machines, chosen by analysis. Nobody annotated which was which.

The biggest margins are consistent everywhere: powmod −98%, factorial −99%, digitsum −90%. These are not close cells and no rotation touches them. binarytrees also shows −98% everywhere — but that cell compares our allocate-once arena against malloc/free-per-node C, so its margin measures a memory protocol, not codegen; we count it in the Bend comparison (both ports naive there) and disclose it anywhere the C column is read.

Why this isn’t “just write it in Zig”

The fair question. On sequential kernels the honest answer, after chasing every gap to its mechanism: Koru sits at clang parity on the faithful ports — which is the comparison that matters for a compiler sharing LLVM’s backend — and the two apparent blowout exceptions were measurement artifacts wearing defect costumes. wordfreq’s 4.6× gap was measured against a C entry that never builds a string map at all — it counts into counts[hash % 8] with its vocab array unused. Read the source before you believe a number. Against an honest chained-map C comparator the gap collapses to noise band once a one-line stdlib probe-cache lands (oracle green; the quiet-rig x86 confirmation is a pending measurement, not a claim). hanoi’s 2.2× gap is real but it is not ours: GCC performs deep recursive inlining of self-calls that LLVM will not do for anyone — clang-compiled C on the same source measures 54.8 ms, slower than Koru’s 48.4. We are not behind C on that kernel; GCC is ahead of every LLVM toolchain, and the headroom is a named compiler feature we can adopt rather than a defect we have. What remains is noise-band variation in both directions. LLVM does the lifting for everyone, and a Zig programmer could hand-write either machine we emit. So what did we actually buy?

In Zig, you write the machine. In Koru, you write the proof — and the compiler writes the machine, including choosing which machine. A Zig programmer hand-picks fork/join or work-stealing or sequential and owns the correctness of that choice. Koru’s compiler looked at recursive tors and emitted different runtimes based on proof-derived shape analysis. The safety isn’t annotation-trust: the worklist only fires where purity was proven, so effects can’t be silently reordered by the scheduler. Zig has no type-system concept of “this region is provably pure, therefore it may reduce differently.” Those proofs are Koru’s whole point — obligations, phantom states, ownership — and they are exactly what makes the machine selection honest rather than lucky. The two cells we lose are the cells where the proofs don’t reach — which is a statement about the proof system, not the runtime. And what looked like a sequential gap to C turned out to be the benchmark’s own artifacts — which is now measured, disclosed, and on the record instead of assumed.

What’s still open — honestly

  • tak. Loses everywhere, and the decline rule that’s supposed to keep tak-par at seq-floor measured 85 ms against 45 on the newest board. Fix the regression, then the machine question: permuted three-way recursion needs reduction-granularity stealing. That’s challenge 035 — the defunctionalized machine where every step is a work item.
  • mutual. The fold transform is real and measured a tight win once. It has not reproduced. Either the variance is machine noise or the par port has a bimodal scheduling pathology — the ±12.9 ms stddev says the measurement itself is broken before the verdict is.
  • The benchmark’s own comparators. Two of the board’s flashiest cells measure artifacts, not languages: binarytrees compares our allocate-once arena against malloc/free-per-node C — the suite itself discloses that allocation pressure is not measured — and wordfreq’s fast C entry never materializes a string map. The board needs honest comparators (a chained-map C entry exists; an arena C entry should too) before its C column can be read as a verdict rather than a defect detector.
  • Recursive inlining. GCC’s deep recursive inlining of self-calls is the mechanism behind hanoi/fib’s GCC-only speedups — proven in x86 assembly, shared by no LLVM toolchain. Adopting it in koruc is real headroom and a compiler feature, not a bug fix.
  • Effects don’t ride the machine yet. Today’s worklist fires only for proven-pure tors. Bend’s IO.OP made effects first-class machine states via a monad; Koru’s version — discharged obligations as work-item witnesses — is designed but unbuilt.

The receipts

Everything above is reproducible: koru-benchmarks runs run.sh (oracle gate — every kernel must print its expected integer) then bench.sh (hyperfine per toolchain → results/latest.json), and scripts/bench-on-hetzner.sh provisions a dedicated CCX box, builds the pinned Docker rig, runs the board, pulls the artifact back, and self-destructs the server. Three boards survive from 2026-11-24: results/droplet/2026-11-24_hetzner_nbg1_ccx43_koru-main.json, results/droplet/2026-11-24_hetzner_hel1_ccx43_koru-tak-wl-spike.json, and the fsn1 board whose artifact hash is 30d7678a84330602fc50bffa4901980f7620266cc4005711864e7660c0c7850c — 164 measured cells, zero wrong answers, server destroyed after the pull. The compiler commits are public in the Koru repo: the spawned-flag and probe/permit fixes, the work-size floor, the worklist lowering, the asymmetry gate, the unsure-shape decline (whose regression is documented above), each with its measurement in the commit message.

The short version: a language that hadn’t changed its surface in months just proved it was consolidating, not calcifying — by learning to be more than one machine, and by measuring itself honestly enough that this post had to be rewritten when the numbers didn’t reproduce. Koru is ahead on 20 of 22 cells, on every board, in every datacenter we rented. tak is Bend’s, fair and square. The twenty-first cell doesn’t exist yet — and when it does, it’ll be because one board said so, not because three of them were averaged into a nicer story.