Skip to content

perf(ci): benchmark real workload shapes, with the parse caches off (closes #2096) - #2098

Merged
robcohen merged 4 commits into
mainfrom
perf/bench-pr-shapes
Aug 19, 2026
Merged

robcohen merged 4 commits into
mainfrom
perf/bench-pr-shapes

Conversation

@robcohen

Copy link
Copy Markdown
Member

Closes #2096.

The gap

The benchmark generated its own ledger inline, and every transaction in it was a plain two-posting expense — no cost specs, no lots, no reductions. Booking and the entire inventory engine ran zero times. scripts/gen-profile-workload.py already documents this exact workload as "the floor, not the benchmark" and records that it leaves booking at 0.3% of instructions. The benchmark was measuring the floor.

#2094 made the comparison trustworthy. This makes the workload representative.

Proof it works

Same two binaries — current main as base, the commit before #2085 (the plan_ordered quadratic) as the PR — through the new report:

Shape base this PR Change
simple 94.7ms ± 5.5ms 93.4ms ± 3.9ms -1.4% ✅ within noise
investment 127.7ms ± 7.7ms 128.7ms ± 5.9ms +0.8% ✅ within noise
fifo 116.9ms ± 4.2ms 2207.3ms ± 49.6ms +1788.9% 🔴 regression

simple is what the old benchmark measured, and it reads within noise. An 18x regression in lot selection shipped invisibly. The comment now also leads with a banner naming the affected shapes.

Two things found while building it

Both tools were measured warm. bean-check writes a .picklecache, rledger writes its own binary cache, and hyperfine's warmup populates both — so every measured run was a cache hit. On fifo that is 18.4s cold against 0.3s warm, and rledger's cache short-circuits the parser, which is most of what check does. A parser regression was invisible regardless of workload. Disabled via BEANCOUNT_DISABLE_LOAD_CACHE, which is Python beancount's own variable that rledger deliberately honors, so one setting covers both tools. The headline changes accordingly — fifo is 160.9x faster than beancount, not the 4.1x a warm cache reports.

beancount cannot load every shape. investment fails under bean-check (#2097, filed separately — rustledger's STRICT accepts an ambiguous lot match beancount rejects). The workflow now tests whether bean-check succeeds per shape rather than assuming it, and times rledger alone where it does not. Timing a run that exits early would have produced a flattering number for a comparison that never happened.

Also

The comment body is built by the step that computes the numbers and read from disk, instead of being assembled in JavaScript from ~15 interpolated step outputs. That indirection is how the footer came to claim "5 runs, 2 warmup" for a run using 20 and 3 — nothing tied the string to the value it described. Shape descriptions are imported from the generator, so the comment cannot describe a workload differently from the thing that produced it. An empty result set is now a hard error rather than a well-formed comment that happens to say nothing.

Budget

Measured on #2094's runs: 4–8 minutes against a 30-minute timeout, dominated by the two release builds, which extra shapes do not repeat. Cold beancount adds ~80s (fifo is 18.4s per run, hence 3 runs and 1 warmup for beancount against 20 and 3 for the rledger pair — it is the context number, not the regression signal).

Validated locally end-to-end: the full pipeline was run against all three shapes with real hyperfine output, the empty-result guard was confirmed to fire, and the regression detection is the table above.

Closes #2096.

The PR benchmark generated its own ledger inline, and every transaction in
it was a plain two-posting expense: no cost specs, no lots, no reductions.
Booking and the whole inventory engine ran zero times, so the quadratics
fixed in #2083, #2086 and #2091 could not have appeared here however sound
the comparison was. `gen-profile-workload.py` already documents its
`simple` shape as "the floor, not the benchmark" and notes it leaves
booking at 0.3%; the inline generator was that floor, used as the
benchmark.

It now generates `simple`, `investment` and `fifo` through that script —
the same one `profile.yml` uses, so a run is reproducible locally — and
reports each shape on its own row against its own base, with the
significance test applied per shape so a regression in one cannot be
diluted by the others holding steady.

Two things found while building it:

**Both tools were being measured warm.** bean-check writes a
`.picklecache` and rledger writes its own binary cache, and hyperfine's
warmup populates both, so every measured run was a cache hit. On `fifo`
that is 18.4s cold against 0.3s warm — a 60x difference — and rledger's
cache short-circuits the parser, which is most of what `check` does. A
parser regression was invisible regardless of workload. Both are now
disabled through `BEANCOUNT_DISABLE_LOAD_CACHE`, which is Python
beancount's own variable that rledger deliberately honors, so one
setting covers both. The headline moves accordingly: `fifo` is 160.9x
rather than the 4.1x a warm cache reports.

**beancount cannot load every shape.** `investment` fails under
bean-check (#2097), so the workflow tests for that per shape rather than
assuming it, and times rledger alone where bean-check errors. Timing a
run that exits early would otherwise have produced a flattering number
for a comparison that never happened.

The comment body is now built by the step that computes the numbers and
read from disk, instead of being assembled in JavaScript from ~15
interpolated step outputs. That is how the footer came to claim "5 runs,
2 warmup" for a run using 20 and 3: nothing tied the string to the value.
An empty result set is now a hard error rather than a well-formed comment
that happens to say nothing.
Copilot AI lite review requested due to automatic review settings August 19, 2026 15:45
@robcohen
robcohen requested a review from a team as a code owner August 19, 2026 15:45
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.

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 benchmark GitHub Actions workflow to measure rustledger on representative, real-world workload “shapes” (including booking/inventory-heavy cases) with load caches disabled, and to publish a per-shape report assembled from the measured artifacts.

Changes:

  • Replace the inline “simple-only” heredoc ledger generator with scripts/gen-profile-workload.py and run multiple workload shapes (simple, investment, fifo).
  • Run hyperfine per shape (PR vs base) and optionally time beancount only when it can successfully process that shape; disable load caches via BEANCOUNT_DISABLE_LOAD_CACHE.
  • Generate the PR comment body from on-disk JSON artifacts in a Python step (instead of stitching many ${{ }} outputs in JavaScript) and hard-error on missing results.

💡 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
Comment thread .github/workflows/bench-pr.yml Resolved
@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!

@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 71.6ms ± 2.0ms 713.4ms ± 5.2ms 10.0x 36.9 MB / 50.0 MB
investment 94.1ms ± 1.5ms — — 37.8 MB / n/a
fifo 89.5ms ± 1.1ms 15576.6ms ± 447.7ms 174.1x 37.2 MB / 57.8 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 71.0ms ± 2.7ms 71.6ms ± 2.0ms +0.8% ✅ within noise 35.8 MB → 36.9 MB (+3.1%)
investment 95.5ms ± 1.6ms 94.1ms ± 1.5ms -1.4% ✅ within noise 37.7 MB → 37.8 MB (+0.2%)
fifo 88.4ms ± 1.1ms 89.5ms ± 1.1ms +1.2% ✅ within noise 37.1 MB → 37.2 MB (+0.3%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 1.5ms, investment 1.0ms, fifo 0.7ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

This PR changes a workflow file and nothing else, so both sides were
built from identical Rust source — and the first run reported `simple`
at +3.1%, clearing both tests and printing a colored verdict for a
difference that no code caused.

The standard error only describes variance WITHIN a run. Two binaries
built from the same source still differ run to run through code layout,
page placement and a shared runner's neighbors, and that component is
invisible to the SEM: with 20 tight samples a 2ms systematic offset
clears 2σ comfortably. The effect floor is what covers it, so it has to
sit above the observed noise rather than at its edge — and testing three
shapes is three chances to trip it.

Observed identical-build differences: +3.1% in CI, and -3.3%, +3.0%,
+2.5%, -2.5% locally. 5% covers those. Re-verified in both directions:
the pre-#2085 quadratic still reports +1788.9% on `fifo`, and every
identical-source pair now reads within noise.
@robcohen

Copy link
Copy Markdown
Member Author

Self-validation, since this PR runs the workflow it changes (thanks to #2094's paths fix).

Run 1 — rejected outright. No jobs created, only "this run likely failed because of a workflow file issue". The cause: the JS 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. yaml.safe_load accepts the file happily; actionlint names the line. Fixed in 7032322.

Run 2 — worked, and reported a false positive. Full report, all three shapes, investment correctly skipped for beancount, fifo at 167.5x. But simple came back +3.1% 🟡 slower on a PR that changes one YAML file, so both sides were built from identical Rust source.

That is the floor being too low, not the test being wrong. The standard error describes variance within a run; two binaries from the same source still differ between runs through code layout, page placement and a shared runner's neighbors, and the SEM cannot see that component — with 20 tight samples a 2ms systematic offset clears 2σ easily. Raised to 5% in d835a69, with the measurements that justify it in the commit message rather than a round number picked by feel.

Run 3 — clean. All three shapes within noise, spreads of ±0.6–1.0ms this time, which is itself the evidence: the +3.1% was between-run variance, not code.

Re-verified in both directions after the change — the pre-#2085 quadratic still reports +1788.9% 🔴 on fifo, and every identical-source pair reads within noise. A benchmark that cannot be shown to report dirty is not evidence, and neither is one that reports dirty when nothing is.

@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

…wo cold runs

Review feedback, both valid.

`BENCH_SHAPES` was stated in four step env blocks, so generation, timing,
RSS and the report each carried their own copy of the list and could
drift apart. That is the same defect this PR already fixes in the footer,
which claimed a run count nothing tied it to. Hoisted to job level, along
with `BENCH_WARMUP` for the same reason — hyperfine consumes it and the
comment reports it back.

The bean-check eligibility probe is a full cold run of the workload, and
hyperfine then did its own warmup run on top: two cold runs where one
would do, which on `fifo` is 18 seconds of pure waste. Beancount's warmup
is now 0, with the probe serving as it. Representativeness is unchanged —
with the parse caches disabled the probe cannot leave a picklecache, so
it warms the page cache and Python's imports and nothing else, which is
exactly what the warmup it replaces did.
@robcohen
robcohen merged commit 6acff88 into main Aug 19, 2026
55 of 56 checks passed
@robcohen
robcohen deleted the perf/bench-pr-shapes branch August 19, 2026 16:25
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.

[Perf]: the PR benchmark's workload has no cost postings, so booking and inventory regressions cannot show up

2 participants