Repository navigation
perf(loader): run reintern_directives on fresh-parse path + drop dead SyncStringInterner - #1081
Merged
Merged
Conversation
… SyncStringInterner (closes #1071) The cache-hit path already ran reintern_directives after deserializing to deduplicate InternedStr across files; the fresh-parse path did not. So multi-file ledgers parsed from source had identical account / currency / tag strings landing in distinct Arc<str> allocations (per-file StringInterner), defeating the Arc::ptr_eq fast path in InternedStr::PartialEq and forcing every cross-file equality through byte comparison. Changes: (1) Extract reintern_directives and reintern_plain_directives from the feature-gated cache module into a new always-on dedup module. The dedup walk has no rkyv/cache dependency; gating it behind the cache feature was incidental. lib.rs now re-exports both functions unconditionally. (2) Call dedup::reintern_directives at the end of Loader::load, so every consumer of LoadResult sees a deduplicated directive list regardless of whether they came in via cache or fresh parse. (3) Drop SyncStringInterner from rustledger-core::intern. The type had zero call sites in the workspace; an audit for #1071 confirmed it was dead code. Removing it also lets us drop the parking_lot dependency from rustledger-core (added in #1076 specifically for this type). Tests: * New test_fresh_parse_deduplicates_internedstr_across_files locks in the cross-file dedup invariant via VirtualFileSystem (two files referencing Assets:Bank; assert the resulting Posting and Open share an Arc via InternedStr::ptr_eq). * Existing reintern unit tests in cache.rs continue to pass against the moved implementation. Closes #1071 Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-05-11)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves cross-file InternedStr deduplication by ensuring the fresh-parse loader path runs the same reinterning pass as the cache-hit path, and removes unused thread-safe interner code from rustledger-core (dropping the parking_lot dependency there).
Changes:
- Extracted
reintern_directives/reintern_plain_directivesinto a new always-ondedupmodule and re-exported them fromrustledger_loader. - Updated
Loader::loadto rundedup::reintern_directiveson the fresh-parse path, aligning behavior with cache-hit flows. - Removed dead
SyncStringInternerfromrustledger-coreand droppedparking_lotfromrustledger-coredependencies; added a regression test for cross-file account dedup.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-loader/src/lib.rs | Calls reinterning on fresh parse; adds regression test; updates re-exports. |
| crates/rustledger-loader/src/dedup.rs | New always-on dedup module containing reinterning walkers. |
| crates/rustledger-loader/src/cache.rs | Removes reinterning implementation from cache module; updates tests to import from dedup. |
| crates/rustledger-core/src/intern.rs | Removes unused SyncStringInterner implementation and its test. |
| crates/rustledger-core/Cargo.toml | Drops parking_lot dependency (no longer needed). |
| Cargo.lock | Reflects dependency graph update after removing parking_lot from rustledger-core. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 98% |
| Full AST Match | 99% |
| Total Files | 786 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
Three concerns, all valid: (1) Coverage gap. The pre-Copilot reintern_directive only walked posting-level account/currency fields. It silently skipped: - Transaction.payee - Transaction.narration - Transaction.tags - Transaction.links - Document.tags - Document.links Cross-file PartialEq on those fields fell through to byte compare. Expanded the walk to cover all six. Extracted an intern_vec helper for the Vec<InternedStr> cases. (2) Double hash lookup. do_intern called contains() then intern() — two probes per call. Added StringInterner::intern_with_status which returns (InternedStr, was_new) from a single probe. Replaces the existing two-call dance. (3) Misleading docs. Module docs and Loader::load comment claimed account/currency/tag coverage, but the implementation skipped the tag/link/payee/narration cases. Updated both to reflect the actual (now-correct) full coverage. Plus a new regression test test_fresh_parse_deduplicates_transaction_fields_across_files that references the same payee + tag across two included files and asserts ptr_eq on both — pre-Copilot fix this would have failed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1071.
Re-framed from the issue's original "API lockdown" proposal after the audit found:
InternedStr::new/From<&str>are used in ~30 constructor signatures (Posting::new(impl Into<InternedStr>, ...), etc.) and dozens of.into()call sites. A full lockdown would shatter the API surface for marginal benefit.reintern_directivesto deduplicateInternedStracross files (each file has its own per-fileStringInterner, so identical account / currency / tag strings start out in distinctArc<str>allocations). The fresh-parse path didn't run it, leaving every cross-file equality check falling through to byte comparison instead ofArc::ptr_eq.SyncStringInterneris dead code — zero call sites in the workspace.Change
dedupmodule —reintern_directives+reintern_plain_directivesextracted from feature-gatedcachemodule into an always-on module.cachewas incidental. Both functions remainpuband re-exported fromlib.rsso external callers (rustledger'scheckcommand,rustledger-wasm) keep working.Loader::loadcallsdedup::reintern_directivesautomatically at the end.LoadResultsees a deduplicated directive list.SyncStringInternerfromrustledger-core::intern.parking_lotdep fromrustledger-corethat was added in #1076 specifically for this type.Why not the literal "API lockdown"?
The issue's original proposal was to make
InternedStr::newpub(crate)and drop theFrom<&str>impls. After the audit:InternedStr::new/::fromsites: 9 (5 tests, 1 rkyv deserialize, 1 validator, 1 parser empty-tag fallback, 1 directive test).impl Into<InternedStr>constructor signatures: ~30, depending onFrom<&str>being available..into()callers: dozens.Even with the lockdown, plugin-emitted directives still go through
.into()(no plugin-facing interner story), so the type-safety win would be hollow. Runningreintern_directivesautomatically captures both legitimate non-interned construction (test fixtures, plugins) and the cross-file gap, which is what actually matters for theArc::ptr_eqfast path.Tests
test_fresh_parse_deduplicates_internedstr_across_files— lock in the invariant viaVirtualFileSystem: two files referenceAssets:Bank, assert the resultingOpen.accountandPosting.accountshare oneArcviaInternedStr::ptr_eq. This test fails pre-fix.cache.rscontinue passing against the moved implementation (they now import fromcrate::dedup::reintern_directives).Public API
pub fn reintern_directivesandpub fn reintern_plain_directivesare now exported fromrustledger_loaderunconditionally (previously gated behindcachefeature). Any caller that imported them throughrustledger_loader::reintern_directiveskeeps working.SyncStringInternerremoved fromrustledger_core. Zero workspace consumers; this is a clean break for any out-of-tree dependent that happened to use it (unlikely given it was unused in our own code).Test plan
cargo test -p rustledger-loader --all-features— 137 tests pass (new dedup test included)cargo check --workspace --all-features --all-targets— cleancargo fmt --all -- --check— cleancargo clippy -p rustledger-core -p rustledger-loader --all-features --all-targets -- -D warnings— clean🤖 Generated with Claude Code