CI: fail pull requests whose benchmark ratios regress #16
Loading…
Reference in a new issue
No description provided.
Delete branch "bench-regressions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Benchmark regressions in CI:
npm run bench:check, plus a Forgejo workflow that runs it on pull requests.What it does
scripts/bench-check.mjsruns:npm run bench:match(...)through the transform against a hand-written switch. The README says that ratio is about 1x (it's 4–6x without the transform), so the check is that it doesn't grow.npm run bench:loops: callbacks against loops for every case and size. The four chains the transform rewrites (forEach, map, filter.map.reduce, filter.map.some) must keep their advantage.filter,reduceandsomeare printed asinfoonly, because no claim depends on them moving either way.docs/(errors, inline ×2, loops, shapes; and whatever PRs add later). Each is built the waydocs/.vitepress/config.mtsbuilds it (as written vs the native transform's output, or the twocompareexamples) and timed the waytheme/bench.worker.tstimes it: batches of at least 25 ms, 12 alternating rounds, median, ×3. If the variants return different results, the check fails.It compares each ratio to
scripts/bench-baseline.json, never absolute ns. The runner is shared and isn't the machine the baseline came from, but two variants timed in the same run on the same machine still compare, and the ratios are what the docs claim.Tolerance, and why it's loose
A ratio fails when it is more than 2x past its baseline in the direction that breaks its claim. A ratio can have its own tolerance;
filter.map.someat 1,000 elements has 3x, because it's bimodal here (35x or 69x). When anything fails, everything is measured again and each ratio keeps the better of its two results, so a single noisy stretch doesn't fail the build.This catches a rewrite that stops happening (loops.md's 3.6x falling to 1x,
matchgoing back to 4–6x) or a docs claim the engine broke. It won't catch a 10–20% drift, and the ratios near 1x (map at 10/1,000 elements) can only fail if they really collapse. The README note says so.Before picking the tolerance I measured each ratio's spread over 5 runs (max/min up to 1.5, plus the one bimodal case). The baseline is the median of those 5 runs (Node 26.13).
npm run bench:check -- --updaterewrites it and keeps per-ratio tolerances.Tested here
--updatethere) or a per-ratio tolerance. I'll check the run.Files
scripts/bench-check.mjs,scripts/bench-baseline.json,.forgejo/workflows/bench.yml(pull_request + workflow_dispatch; Node 26, Rust,npm ci, napi build,npm run bench:check, styled after pages.yml), thebench:checknpm script, and a README note under "Run it".Not done / uncertain
newuntil the baseline is updated after they merge. A ratio with no baseline doesn't fail.🤖 Generated with Claude Code