Skip to main content

Stability Over Bragging Rights

devlog
programming
performance
Warm-ups, LuaJIT variance, 201-run sweeps, and why a single median is a poor way to talk about compiler performance.
Published

November 26, 2026

I have a notes file full of benchmarks where luacomp looks good. Some of those numbers are useful. A few of them are mostly noise wearing a suit.

The problem is not that the medians were wrong. It is that a median is a very small story to tell about a program that runs thousands of times in a game loop. If the distribution has a long tail, the median can be calm while the player sees a hitch. If the first run pays a one-time Windows cost, a single “before and after” screenshot can turn an environment event into a fake compiler result.

So I stopped treating one number as the result. I added two stability harnesses and ran them long enough to be uncomfortable: 51 runs for the usual check, 201 runs when I wanted to stop arguing with noise.

Warm-up separates a cold artifact from steady state

The number that was not real

The first stability pass had 51 runs per workload, no warm-up, and a very impressive amount of variance: 180–292% CV, with maxima between 95 ms and 427 ms. That is not a compiler signal. That is a freshly written executable getting introduced to Windows.

When I isolated a single new binary, the shape was obvious:

Run Time
first run after build 91.6 ms
next runs 4.8–5.2 ms

The first run was doing AV scanning, page-cache work, and whatever else the OS decides to do when a new file appears. The next runs were the program I actually wanted to measure.

This is why the harness now warms both engines before it records anything. It does not average the cold start into the answer. It throws that run away and says so out loud.

# Generalized commands; point these at your own toolchain.
$env:LUACOMP = "<path to luacomp>"
$env:LUAJIT = "<path to luajit>"
powershell -NoProfile -ExecutionPolicy Bypass -File .\tests\stability.ps1 -Repeat 201

What I actually report now

tests/stability.ps1 launches each benchmark many times per engine, with a high-resolution stopwatch around the process. Process startup is included for both engines, so the comparison is fair, but the absolute number is not a pure Lua number.1

For each engine it reports:

Field Why I care
median The usual steady-state answer.
p95 / p99 What the slow tail looks like before the worst case.
max The one run a person is most likely to remember.
stddev and CV Whether the median is sitting on a narrow or wide pile.
tail ratio max / median; a compact way to spot a long right side.
outliers Counts above median * 1.5.

The harness also separates the labels. A workload can be slower and still be stable. Calling that “unstable” would be dishonest, because slowness and unpredictability are different failures.

The actual gate is deliberately plain:

if ($compilerStats.CV -gt 10.0 -and
    $compilerStats.CV -gt $jitStats.CV * 1.5) {
  $stability = "unstable"
}
elseif ($compilerStats.Tail -gt [math]::Max(1.5, $jitStats.Tail * 1.5)) {
  $stability = "tail"
}

$speed = "same"
if ($ratio -gt 1.25) { $speed = "slower" }
elseif ($ratio -lt 0.8) { $speed = "faster" }

No model, no vibe, no “looks fine to me”. Just thresholds I can explain.

Speed and stability are separate axes

That little map is the mental model I wish I had written down earlier. The goal is not merely the left side or the right side. It is the top-right box: fast and steady. A slow-but-steady result is a known cost I can park. A fast-but-spiky result is usually a measurement bug waiting to be found.


LuaJIT variance is part of the comparison

One thing I did not expect was how useful it was to watch LuaJIT’s variance too. LuaJIT is not a constant-time oracle. On this machine it has its own warm-up behavior and its own tails.

A clean 51-run interleaved pass showed luacomp faster on len_loop, loop_limit, sort_cmp, typed_call, and upvalue_values. It also showed two real gaps:

Workload luacomp median LuaJIT median
field_access 19.45 ms 7.66 ms
dynamic_values 12.54 ms 7.70 ms

Those gaps are real, but they are not the same thing as instability. The stability label stayed separate.

Then I ran the long pass on field_access:

Engine Median CV
luacomp 20.81 ms 10.7%
LuaJIT 8.55 ms 14.4%

The log recorded 0/1/4 outliers across the reported tail columns. The speed gap was still there, about 2.44x. The variance and tail behavior, though, were LuaJIT-like. In fact LuaJIT’s CV was higher in that pass.

That does not make the gap disappear. It means the next fix is a compiler problem, not a harness problem. I would rather know that distinction before spending a week chasing a ghost.


Isolating game Lua from the renderer

Whole-game benchmarks were lying in a different way. The software renderer dominated them, so changes to Lua execution barely moved the number. Captured game-loop timings went from 12,925.9 ms to 12,895.0 ms for Lumen Vault and from 1,342.3 ms to 1,316.5 ms for Starfall after a real arithmetic fast path. That is a tiny end-to-end change because rasterization is the main character.

So I built a no-op LÖVE stub instead.

The no-op stub isolates Lua logic

The same copied game sources and the same driver.lua run under both engines. The stub:

  • replaces drawing and audio with no-ops;
  • fixes math.random to the same Lehmer stream for both engines;
  • counts draw calls instead of drawing them;
  • prints DRAWS so the harness can check that both engines did the same work.

The luacomp driver is built with --no-love --lua 5.1; LuaJIT runs the same plain Lua driver. If the draw counts do not match, the timing result is not a comparison. It is two different programs wearing the same name.

The long game pass used 201 runs at 300 frames, after three warm-ups:

Mode luacomp median LuaJIT median luacomp CV LuaJIT CV Outliers
idle 37.45 ms 23.56 ms 6.3% 10.3% 0 / 0
demo 38.92 ms 31.00 ms 7.6% 9.8% 0 / 0

So the Lumen Lua logic was more stable than LuaJIT on this machine, while still being 1.59x slower in idle and 1.26x slower in demo. I parked that speed gap on purpose. The user asked for stability coverage, and honestly, this was the more informative result.


Why software rendering stayed out

I did not exclude the software renderer because it was inconvenient. I excluded it because it answers a different question.

The headless renderer is useful for end-to-frame checks: it proved that rendered frame 300 was byte-identical before and after one compiler change, for both games. That is a great correctness gate.

It is a bad lens for Lua stability because:

Question Right harness
Did the final frame stay identical? Headless software renderer
Is Lua execution stable across runs? No-op stub + 201-run sweep
Where does whole-game time actually go? Both, and compare them
Does LuaJIT run the same draw workload? Stub with draw-count gate

The renderer also creates a tempting but wrong conclusion: “the compiler did nothing”. What it really means is “the compiler’s change is small compared to filling pixels”. Those are different sentences.

The stub keeps argument construction, table.sort, coroutines, module state, and temporary tables. That is where the remaining whole-game gap lives. With drawing disabled, the three-engine comparison brings Lumen much closer; the big remaining cost is not boxed arithmetic.


The decision tree I use now

Is the binary freshly written?
├── yes → warm it up, then measure; never report run 1 as steady state
└── no
   ├── Did both engines do the same work?
   │   ├── no  → stop; fix the workload or the stub
   │   └── yes → continue
   ├── Is CV or tail clearly worse than the baseline?
   │   ├── yes → stability bug; inspect the harness before the compiler
   │   └── no  → distribution is comparable
   └── Is the median still slower?
       ├── yes → real speed gap; park it as compiler work
       └── no  → log the win, but keep the tails attached

The important branch is near the top. A work mismatch invalidates the timing before I even look at milliseconds.


What I still do not know

This is one Windows toolchain, one machine, and a handful of workloads. I am not claiming these numbers are universal. AV settings, power management, page-cache state, and CPU frequency can all move the shape.

I also do not know yet whether the field_access gap is one missing representation decision or several small ones. The Stage 5 probe and Stage 7 advisor helped a little, but the honest answer is that equal-content string keys, baked tables, and boxed values still cost more than I want.

What I do know is cleaner than before:

  • Cold starts are not compiler regressions.
  • LuaJIT variance is measured, not assumed away.
  • Speed and stability are separate labels.
  • A no-op stub can isolate Lua work without pretending draw calls do not exist.
  • 201 runs turn “I think this is noise” into a distribution I can discuss.

A single median is a brag. A distribution is an engineering log. I would rather write the second one.

Footnotes

  1. The harness includes process startup for both engines on purpose. It makes the absolute numbers less flattering and the comparison more honest.↩︎