Skip to content

ci(bench): measure the base in the same job instead of reading a stored number - #2094

Merged
robcohen merged 7 commits into
mainfrom
fix/bench-pr-baseline
Aug 19, 2026
Merged

robcohen merged 7 commits into
mainfrom
fix/bench-pr-baseline

Conversation

@robcohen

Copy link
Copy Markdown
Member

Fixes #2090.

The problem

bench-pr.yml measured the PR, then fetched its "main" number from history.json on the benchmarks branch — a value recorded by an earlier nightly, on a different runner, on a different day. The comparison mixed the code change with runner variance:

PR baseline measured verdict
#2085 39.1ms 39.3ms +0.5% ✅
#2088 39.1ms 34.4ms −12.0% 🟢
#2089 39.1ms 41.3ms +5.6% 🟡

The baseline is identical in all three because it is stored, not measured. The measured value swung 20% — and none of those changes can touch the measured path: the benchmark ledger has no cost specs, so #2085 (ordered lot selection) never reaches it, #2088 (BQL executor) is not exercised by check, and #2089 measures flat under cachegrind on five workload shapes and under hyperfine at 1.00–1.02×.

The fix

Build the merge base alongside the PR and hand both to one hyperfine invocation on one runner. Then report a difference only when it clears the combined spread of the two measurements (2σ).

Checked against the three verdicts above, using the standard deviations the workflow itself reported (±1.9ms):

case change gap vs 2σ new verdict
#2085 +0.5% 0.2ms vs 5.4ms within noise ✅
#2088 −12.0% 4.7ms vs 5.4ms within noise ✅
#2089 +5.6% 2.2ms vs 5.4ms within noise ✅
a real 30% regression +29.9% 11.7ms vs 5.5ms reported 🔴

All three false verdicts are suppressed; a genuine regression still lands.

Details

  • Runs 5 → 20. The verdict is now a significance test, and five samples cannot support one. At ~40ms per run this stays well inside the job.
  • fetch-depth: 0, so the base commit is present to build.
  • Timeout 15 → 30 minutes for the second release build. The base builds into its own target dir so the two do not fight over artifacts.
  • The comment now shows both sides with their spreads, and states the noise floor it used.

Why not just raise the threshold

Because the dangerous direction is the false 🟢, not the false 🟡. #2088's −12.0% was spurious for exactly the same reason #2089's +5.6% was, so a genuine regression arriving on a lucky runner would have been reported as an improvement. Widening the band hides more of those; measuring both sides removes the cause.

Verification

The workflow is not fully testable locally, so: the YAML parses, both embedded Python blocks compile, and the github-script body parses under node --check. The significance rule is exercised against the real numbers above.

🤖 Generated with Claude Code

https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr

…ed number

The PR benchmark compared a fresh measurement against a baseline recorded
by an earlier nightly, on a different runner, on a different day. The
comparison therefore mixed the code change with runner variance, and its
verdicts did not survive checking:

    #2085   39.1ms -> 39.3ms    +0.5%  ✅
    #2088   39.1ms -> 34.4ms   -12.0%  🟢
    #2089   39.1ms -> 41.3ms    +5.6%  🟡

The baseline is identical in all three because it was read from
`history.json`; the measured value swung 20%. None of those changes can
touch the measured path — the benchmark ledger has no cost specs, so
#2085 (ordered lot selection) never reaches it, #2088 (BQL executor) is
not exercised by `check`, and #2089 measures flat under cachegrind across
five workload shapes and under hyperfine at 1.00-1.02x.

Now the merge base is built and measured alongside the PR, in one
hyperfine invocation on one runner, and a difference is reported only
when it clears the combined spread of the two measurements (2 sigma).
Against the numbers above, using the standard deviations the workflow
itself reported, that suppresses all three verdicts as noise and still
reports a 30% regression.

Runs go from 5 to 20: the verdict is now a significance test and five
samples cannot support one. The job's budget doubles to 30 minutes for
the second release build.

The false 🟢 is the reason this is worth fixing rather than widening the
threshold. #2088's -12.0% was spurious for exactly the same reason
#2089's +5.6% was, so a genuine regression landing on a lucky runner
would have been reported as an improvement.

Fixes #2090

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Copilot AI lite review requested due to automatic review settings August 19, 2026 12:43
@robcohen
robcohen requested a review from a team as a code owner August 19, 2026 12:43
@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the PR benchmarking workflow to compare the PR against a locally built baseline in the same GitHub Actions job (eliminating runner-to-runner variance from the previous stored-baseline approach), and to report results with basic noise-aware significance gating.

Changes:

  • Builds two release binaries in the same job (current checkout + base commit via git worktree) and benchmarks them together with one hyperfine invocation.
  • Increases sampling (--runs 20, --warmup 3) and job timeout to accommodate the second build and more stable stats.
  • Removes the “fetch baseline from benchmarks branch” step and updates the PR comment to show PR vs base with spreads and a noise floor.
Suppressed comments (1)

.github/workflows/bench-pr.yml:259

  • The explanatory text in the posted PR comment is now out of sync with the workflow: it still says “5 runs, 2 warmup” (but hyperfine uses 20/3), and it says “merge base” even though the workflow builds pull_request.base.sha (base branch HEAD for the PR event). This will confuse readers of the benchmark comment.
              '- **vs base**: The PR and its merge base, built and measured in the same job\n' +
              '- A change is reported only when it exceeds the combined spread of both measurements\n\n' +

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread .github/workflows/bench-pr.yml Resolved
…build

Review of my own diff, two findings.

The significance test compared the gap against two standard deviations of
INDIVIDUAL RUNS, but the quantity being compared is two means, whose
uncertainty is the standard error — smaller by sqrt(runs). At these
numbers that made the test fire only above ~14%, so a real 10% regression
would have been reported as noise. It now uses the standard error of the
difference, which resolves ~3%, plus an effect-size floor of 3% so a
difference that is statistically visible but too small to act on is not
dressed up as a finding.

Worth being explicit that my original validation was against the wrong
scenario: I checked the rule against #2088's -12%, but that gap came from
comparing runners, which measuring both sides in one job removes. The
rule has to be judged on same-runner data, and simulated at 20 runs with
the observed per-run spread it reports +5%, +10% and -12% while treating
identical binaries and a +2% change as noise.

The base also built into its own target directory, which is a cold build
of every dependency and the most likely way this job would have started
timing out. The two commits share a dependency graph, so it now builds
into the same directory and recompiles only the workspace crates.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen

Copy link
Copy Markdown
Member Author

Deep review of my own diff — two findings, and a correction to the description above

The significance test used the wrong dispersion

It compared the gap against two standard deviations of individual runs. The quantity being compared is two means, whose uncertainty is the standard error — smaller by √runs. At the observed spread that made the test fire only above ~14%:

change old rule corrected
2% noise noise
3% noise noise
5% noise report
10% noise report
30% report report

A real 10% regression would have been reported as ✅. Now uses the standard error of the difference (~3% resolution here) plus a 3% effect-size floor, so a difference that is statistically visible but too small to act on is not dressed up as a finding.

My validation was against a scenario this PR removes

The table in the description checks the rule against #2088's −12.0% and calls suppressing it a success. That gap came from comparing different runners, which measuring both sides in one job eliminates. The rule has to be judged on same-runner data — and on that data, suppressing a −12% difference would be a failure, not a success.

Re-validated by simulating 20 runs at the observed per-run spread:

case verdict
identical binaries within noise ✅
+2% within noise ✅
+5% reported
+10% reported
−12% reported

A build risk that would have bitten every PR

The base built into its own target directory — a cold build of every dependency, and the most likely way this job starts timing out even at 30 minutes. The two commits share a dependency graph, so it now builds into the same directory and recompiles only the workspace crates.

Both fixes in bf41c5e.

Third review pass, and a bug I introduced two commits ago.

The memory step reads `./target/release/rledger`. Building the base into
that same directory — which the previous commit did deliberately, to
reuse the dependency artifacts — leaves the BASE binary there. So every
PR would have reported its base's peak RSS under its own name, and the
number would have looked entirely plausible.

It now measures `/tmp/rledger-pr` explicitly, and takes the base's RSS
too, so the comment carries a memory comparison alongside the time one.
That is worth having on its own: the change that closed #2086 halved peak
memory and moved the OOM threshold, and nothing in this report would have
shown it.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
@robcohen

Copy link
Copy Markdown
Member Author

Third review pass — a bug I introduced two commits ago

The memory step reads ./target/release/rledger. The previous commit deliberately builds the base into that same directory (to reuse dependency artifacts), so the base binary is what sits there by the time this step runs. Every PR would have reported its base's peak RSS under its own name — and the number would have looked entirely plausible, which is what makes it worth catching.

Fixed: it measures /tmp/rledger-pr explicitly, and takes the base's RSS too, so the comment now carries a memory comparison next to the time one.

That addition earns its place independently. The change that closed #2086 halved peak memory and moved the OOM threshold from below 20,000 transactions to above it — and nothing in this report would have shown that, because memory was only ever compared against beancount.

Three passes over this diff have now found: the significance test comparing means against per-run spread (would have hidden a real 10% regression), a validation done against the scenario the fix removes, a cold dependency build that risked timing out every run, and this. All from a 155-line workflow change — the shape of thing where nothing type-checks and nothing fails loudly.

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

The paths filter listed only crates/**/*.rs, Cargo.toml and Cargo.lock,
so a PR that edits this workflow skipped the benchmark entirely. #2094 —
three commits reworking how the baseline is built and how significance is
decided — therefore had no benchmark run at all, and would have merged
with its measuring code never once executed.

Add the workflow's own path so a change to the measurement exercises the
measurement.
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 30.5ms ± 1.5ms 24.3 MB
beancount 590.3ms ± 5.8ms 50.7 MB
Comparison 19.3x faster 2.1x less

vs base, measured in this run

Metric base this PR Change
Time 30.3ms ± 2.1ms 30.5ms ± 1.5ms +0.9% ✅ (within noise)
Memory 24.3 MB 24.3 MB +0.0%

A difference counts only when it clears the combined spread of the two measurements (2σ ≈ 1.1ms here).
10K transactions · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs base: The PR and the base-branch commit it is built on, built and measured in the same job
  • A change is reported only when it exceeds the combined spread of both measurements

The footer hardcoded '5 runs, 2 warmup'. The run before this commit used
20 runs and 3 warmup, so the comment stated a methodology that had not
been run — the same class of defect as the stored-baseline bug this PR
exists to fix, in the line that describes the fix.

Warmup and run count now come from one place (step env), and the count in
the footer is read back off the samples hyperfine recorded rather than
restated.
…not measure

Self-review. The memory step parsed peak RSS with an unguarded pipeline,
so anything that stopped the value arriving produced an EMPTY output, and
the comment rendered it as `NaN MB` — or worse, a plausible one: GNU
`time -v` prints a complete report for ITSELF when the command does not
exist, so a missing `/tmp/rledger-pr` would have been reported as ~0.9 MB
of PR memory with nothing to indicate it was wrong. That is the same
failure this PR exists to remove, one step further down.

The command is now resolved before it is measured, and an unparsable
report is a hard error. A non-zero exit from the child is deliberately
NOT an error: a ledger that reports errors still produced a real peak
RSS, and the child's stdout is discarded so it cannot reach the parse.

Also record why the memory delta carries no significance verdict, unlike
the timing one: it is a single sample with no spread to test against.
@robcohen

Copy link
Copy Markdown
Member Author

Filed #2096 for the other half of #2090, found reviewing this PR: the comparison this PR makes trustworthy runs on a workload with no cost postings, so booking and inventory regressions cannot appear in it regardless of how sound the baseline is. Kept separate because it costs job time and this one already does two release builds.

…rrectly

Review feedback. Two things, one real and one wording.

The wording first, because it is the one that matters for a PR about
trustworthy measurement: the commit message and the comment footer both
called this the "merge base". It is not. It is the base branch HEAD, and
that is the CORRECT baseline here precisely because actions/checkout
leaves HEAD at GitHub's merge commit on a pull_request event, so the PR
side already contains the base branch and the difference is the PR's own
changes. Describing it as something it is not made a correct measurement
hard to verify.

The real change: read the base from the checked-out commit's first
parent rather than from the event payload. The payload's base.sha is a
snapshot from when the event fired and can skew from the merge ref the
runner actually checked out; HEAD^1 is by construction what this build
sits on top of. Falls back to the payload when HEAD is not a merge
commit.
@robcohen
robcohen merged commit 7d4fdc6 into main Aug 19, 2026
49 of 50 checks passed
@robcohen
robcohen deleted the fix/bench-pr-baseline branch August 19, 2026 14:42
robcohen added a commit that referenced this pull request Aug 19, 2026
The comment explaining why the body is no longer assembled from
interpolated step outputs contained the literal expression delimiters as
prose. GitHub parses that syntax anywhere in the file, comments included,
and an empty expression is a parse error — so the run failed before it
created a single job, with only 'this run likely failed because of a
workflow file issue' to go on.

Caught because #2094 made this workflow run when it is itself edited.
Local YAML parsing accepts the file; actionlint is what names the line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PR benchmark compares against a stored baseline, so its verdicts are runner noise

2 participants