Skip to content

perf(parser): keep the error oracle linear on many rebuilt entries - #3069

Merged
robcohen merged 1 commit into
mainfrom
fix/oracle-rebuilt-linear
Nov 27, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/oracle-rebuilt-linear

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

The error oracle is now linear in three places where it was quadratic. I found them because test_parse_nested_entries_and_their_tails_parse_in_linear_time timed out under coverage instrumentation on #3066 (10.1 s for 16,000 lines against 0.30 s for 2,000). The cost was already on main, since #3062.

  • with_rebuilt_builder_errors: for each rebuilt entry it scanned every statement of the trace, and for each builder error it scanned every error. Built statements are now a HashSet, and errors are binary-searched by start, with the ones it adds kept in a map.
  • stray-carriage-return and divide-by-zero overlays: they scanned every slot for each error they claimed. They now sort the slots' lines once.

Measurements (release)

Input: $ followed by N copies of 2024-01-02 open\rAssets:Z\n 2024-01-02 open Assets:Z\n. Each copy is two rebuilt entries.

N main this PR
8,000 0.16 s 0.07 s
32,000 3.08 s 0.31 s

32,000 custom "x" 1/0 $ lines take 0.11 s.

Tests and gates

  • Linear-time test: both shapes join the oracle's parse-level linear-time test.
  • No output change: parity is 122,378 of 123,394 inputs, unchanged; the BOM matrix, STRICT_BASELINE and the parser suite pass.
  • No cache bump.

This PR is independent of the others. Merging it first takes the timing flake off the other PRs' coverage runs.

🤖 Generated with Claude Code

with_rebuilt_builder_errors looked each rebuilt entry up by scanning
every statement of the trace, and each of its builder errors up by
scanning every error; the stray-carriage-return and divide-by-zero
overlays scanned every slot for each error they claimed. On 64,000
rebuilt entries with stray `\r`s a parse took 3.1 s (8,000: 0.16 s), and
test_parse_nested_entries_and_their_tails_parse_in_linear_time timed out
under coverage instrumentation in CI.

Built statements are now a set, errors are searched by start, and the
overlays sort the slots' lines once. The two shapes join the oracle's
linear-time test. No output changes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 27, 2026 15:06
@codecov

codecov Bot commented Nov 27, 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

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 53.1ms ± 0.6ms 818.1ms ± 5.2ms 15.4x 43.3 MB / 51.1 MB
investment 81.8ms ± 2.5ms 3077.5ms ± 217.9ms 37.6x 47.4 MB / 59.1 MB
fifo 97.2ms ± 1.8ms 14896.1ms ± 98.1ms 153.3x 49.3 MB / 59.0 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 52.4ms ± 0.5ms 53.1ms ± 0.6ms +1.2% ✅ within noise 42.5 MB → 43.3 MB (+1.8%)
investment 79.8ms ± 0.7ms 81.8ms ± 2.5ms +2.6% ✅ within noise 47.3 MB → 47.4 MB (+0.2%)
fifo 96.8ms ± 1.8ms 97.2ms ± 1.8ms +0.4% ✅ within noise 49.5 MB → 49.3 MB (-0.3%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 0.3ms, investment 1.2ms, fifo 1.1ms), 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

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 180 masked)
Full AST Match 100%
Total Files 828
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

@robcohen
robcohen merged commit e8ac60a into main Nov 27, 2026
64 of 65 checks passed
@robcohen
robcohen deleted the fix/oracle-rebuilt-linear branch November 27, 2026 17:01
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.

1 participant