Skip to content

test(core): shrink the slow rustledger-core tests under Miri - #2939

Merged
robcohen merged 3 commits into
mainfrom
fix/miri-metadata-bulk-test
Nov 11, 2026
Merged

robcohen merged 3 commits into
mainfrom
fix/miri-metadata-bulk-test

Conversation

@robcohen

@robcohen robcohen commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

What

Shrink the three rustledger-core unit tests that are too slow under Miri, keeping each one's property meaningful at the smaller size. The native run is unchanged.

  • metadata::tests::test_bulk_paths_are_not_quadratic and test_build_keeping_first_keeps_each_keys_first_entry: N = 1,000 instead of 50,000 under cfg(miri). A quadratic path still exceeds the 10 * N comparison bound (N^2/2 = 500,000).
  • inventory::tests::for_each_strict_subaccount_visits_exactly_the_strict_subtree: under cfg(miri) the generated account tree is three levels deep with full fan-out under each level's first parent (830 names instead of 8,655), and every 23rd name is a query (41 instead of about 1,240). Every root and segment shape is still present, and a filtered scan still reads over four times the 200-key bound.

Why

The weekly Miri job (miri.yml, tracked by the scheduled-workflow health issue #2748) times out at its 40-minute budget. The first fix shrank the metadata tests, but dispatched run 42963735396 still timed out: the subaccount test ran for over 37 minutes before the job was killed, and the metadata tests come later alphabetically, so CI never reached them. That test's oracle filters every name per query, about 10.7 million prefix checks, each a long run of interpreted steps under Miri.

miri.yml asks for slow unit tests to be shrunk under cfg(miri) rather than skipped, so no test is ignored.

How it was checked

  • A local Miri run of the whole core lib under cargo miri nextest (nightly 2026-11-10, CI's MIRIFLAGS) found no other outlier. Calibrated against the per-test timestamps of run 42963735396, every other test costs a few seconds of CI time, and the 171 tests CI never reached add up to about 90 s.
  • Native: cargo test -p rustledger-core --all-features, clippy --all-features --all-targets -D warnings, and treefmt pass.
  • A workflow_dispatch run of miri.yml on this branch.

Closes the Miri entry of #2748.

🤖 Generated with Claude Code

The weekly Miri job timed out (40 minutes) in
`test_bulk_paths_are_not_quadratic`, which builds 50,000 metadata entries.
Miri's per-step cost makes that size too slow; shrink it, and the sibling
`test_build_keeping_first_keeps_each_keys_first_entry`, to 1,000 under
`cfg(miri)`, as miri.yml asks for slow unit tests. A quadratic path still
exceeds the 10 * N comparison bound at that size, so the tests keep their
meaning there; the native run is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 11, 2026 05:08
@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 50.8ms ± 0.7ms 714.4ms ± 3.8ms 14.1x 45.0 MB / 51.1 MB
investment 77.6ms ± 0.6ms 2715.3ms ± 39.0ms 35.0x 46.9 MB / 59.1 MB
fifo 76.5ms ± 3.2ms 15188.9ms ± 437.7ms 198.6x 48.9 MB / 58.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 50.3ms ± 0.4ms 50.8ms ± 0.7ms +1.0% ✅ within noise 44.1 MB → 45.0 MB (+2.0%)
investment 77.3ms ± 0.4ms 77.6ms ± 0.6ms +0.3% ✅ within noise 47.1 MB → 46.9 MB (-0.4%)
fifo 75.8ms ± 0.7ms 76.5ms ± 3.2ms +0.9% ✅ within noise 49.2 MB → 48.9 MB (-0.5%)

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

@codecov

codecov Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger-core/src/inventory/mod.rs 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 826
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 dispatched Miri run still timed out at 40 minutes, now inside
`for_each_strict_subaccount_visits_exactly_the_strict_subtree`, which ran
for over 37 minutes before the job was killed (the metadata tests come
later alphabetically and were never reached). Its oracle filters every
name per query: about 1,240 queries over 8,655 names, 10.7 million prefix
checks, each a long run of interpreted steps under Miri.

Under `cfg(miri)` the generated tree is three levels deep with full
fan-out under each level's first parent (830 names) and every 23rd name
is a query (41 in all). Every root and segment shape is still present,
and a filtered scan still reads over four times the 200-key bound, so
the test keeps its meaning. The native run is unchanged.

A local Miri run of the whole lib under nextest found no other outlier:
every other test is a few seconds of CI time.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen robcohen changed the title test(core): shrink the metadata bulk-path tests under Miri test(core): shrink the slow rustledger-core tests under Miri Nov 11, 2026
@robcohen
robcohen merged commit f4571fa into main Nov 11, 2026
59 of 60 checks passed
@robcohen
robcohen deleted the fix/miri-metadata-bulk-test branch November 11, 2026 19:47
robcohen added a commit that referenced this pull request Nov 11, 2026
Brings in #2939 and #2942. CHANGELOG conflict in Fixed resolved by
keeping both entries. Cache versions unchanged: loader 71, WASM 99.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
robcohen added a commit that referenced this pull request Nov 12, 2026
#2945, which this branch carried, is squash-merged as 526f833; its
hunks take main's final form (loader cache v71, `escape_untrusted_text`
in `rledger query`, its CHANGELOG notes).

With #2947: the FFI's `semantic_validation_errors` keeps #2947's
`booking_refused` set-aside and its `is_advisory_only` filter, which
replaces this branch's equivalent one. `convert::surface_agreement` now
matches each finding's code too (the 4.0.0 wire error carries it) and
runs `validate-file` and `load-file` over the shared cases, so the file
surfaces are pinned to leave out E1004 and set a refused transaction
aside.

No cache moves: the loader cache stores only error-free raw loads, and
this branch changes no WASM output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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