Repository navigation
perf(extract): load each --ledger/--existing ledger once per run - #2524
Conversation
The --ledger profile reader, the currency lookup for an entry without `currency`, and --existing dedup each called rustledger_loader::load themselves, with the same options, so one ledger given as both flags was parsed and booked three times per import. A per-run `Ledgers` cache now loads each path once and hands it to every reader; dedup, the last one, takes it by value so its transactions are not cloned. Each consumer still formats its own error from the cached result, at the point in the run where it did before, so every message names the same flag in the same order. On a 50,000-transaction ledger given as both flags: 1.38 s -> 0.50 s CPU, 158 MB -> 106 MB peak RSS. Closes #2503 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Review (adversarial pass)The cache is keyed by the path as given, so Checked that dedup's Cross-PR integration (applies to #2524, #2526, #2527, #2531, #2532, #2533)All six PRs were merged onto
|
What changed
rledger extractnow loads each--ledger/--existingpath once per run and shares theLedgerbetween its three readers:--ledgerprofile reader (ledger_profile::load_profiles),currency(resolve_entry_currency→ledger_profile::open_currencies),--existingdedup (duplicate::load_existing).A new per-run cache,
extract_cmd::ledgers::Ledgers, storesrustledger_loader::load'sResultkeyed by path. All three readers already used identical options (run_plugins: false,validate: false), and those options now live in one place. Dedup is the last reader, so it takes the ledger out of the cache by value and keeps its transactions without cloning them.Why
One ledger given as both
--ledgerand--existingwas parsed and booked three times per import (#2503).Messages unchanged
Each consumer still turns the cached result into its own message, naming its own flag, at the point in the run where it did before. Only the load is shared:
--existingwarning (--existing ledger … has N error(s)), printed at dedup time;no \open …` directive loaded from …, which has N load error(s)`, from the currency lookup;Failed to load existing ledger: …, with the loader error as its cause (dedup takes ownership, so theanyhowcontext chain is intact);failed to load ledger …/cannot be read for importer profiles.The existing tests for each message pass unchanged.
Measured
Release builds of
origin/mainand this branch, on a 50,000-transaction ledger, importing a 2-row CSV with--importer bank --ledger L --existing L(an entry withoutcurrency, so all three readers run). The machine was heavily loaded (load average ~34 on 8 cores), so CPU time is the comparable number, not wall time:With
--existingalone (one load on both): 0.90 s on main, 0.50 s here. Most of that 0.40 s is the second load: on that path main loads--existingin both the currency lookup and dedup.How tested
each_ledger_is_loaded_once_per_run: runs the real pipeline throughrun_with_ledgersand checks the cache's load counter. One path given as both flags loads 1 time (it was 3 before), and two different paths load 2 times. It also checks the output: the currency comes from theopen, the duplicate is skipped and the new row is kept. Shown to fail without the fix: with caching turned off inLedgers::index, it fails withleft: 3, right: 1.cargo test -p rustledger --all-features: all pass (529 lib tests).cargo clippy --workspace --all-features --all-targets -- -D warnings: clean.RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p rustledger --all-features: clean.Not changed: a ledger that relies on
plugin "auto_accounts"still has noopenfor the account, since plugins stay off for these loads (see #2503).Closes #2503
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr