Repository navigation
perf(parser): skip LSP-only occurrence collection on the load path (-23MB heap, -2.6% instructions) - #1590
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📊 Benchmark Results
vs main branch (2026-06-25)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
Improves loader/CLI performance by avoiding construction of LSP-only currency_occurrences / account_occurrences indices during parsing on the load path, while keeping the existing parse() behavior unchanged for editor/LSP usage.
Changes:
- Add
parse_without_occurrences()(and underlyingparse_via_cst_opts(..., collect_occurrences)) to allow parsing without collecting occurrence indices. - Thread
collect_occurrencesinto the CST descendant walk to skip per-token allocations and ancestor probes when occurrences aren’t needed. - Update the loader to use
parse_without_occurrences()and add a regression test for semantic equivalence (minus occurrences).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger-parser/tests/parser_integration_test.rs | Adds a regression test covering the new lean parse path. |
| crates/rustledger-parser/src/lib.rs | Exposes parse_without_occurrences() at the public API level. |
| crates/rustledger-parser/src/cst/mod.rs | Re-exports the new CST parse entry point with options. |
| crates/rustledger-parser/src/cst/convert.rs | Implements parse_via_cst_opts and gates occurrence collection in walk_descendants_once. |
| crates/rustledger-loader/src/lib.rs | Switches loader parsing to the lean variant to realize the allocation/CPU savings. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
0e859f5 to
0136c04
Compare
|
Both addressed: (1) the assertions now compare full |
…23MB, -2.6%) currency_occurrences/account_occurrences are consumed only by the LSP, but the loader/CLI pipeline collected them anyway -- walk_descendants_once built a Spanned<Account>/Spanned<Currency> (+ an in-ERROR_NODE ancestor walk) per ACCOUNT/CURRENCY token, the #1 allocation-count site. Add parse_without_occurrences (collect_occurrences=false) and point the loaders two parse sites at it; parse() is unchanged so the LSP keeps full data. Measured on 10k txns: -23.6MB heap (-14.9%), -40072 allocations, -29.1M instructions (-2.6%). Regression test + 280 parser / 89 loader tests pass.
6238175 to
b25ef7c
Compare
parse_via_cst_opts is pub; rustdoc -D warnings rejects a public doc linking to the private walk_descendants_once. Use a plain code span instead of a link.
What
Profiling-driven optimization ④ — the biggest yet. Skips collecting the
currency_occurrences/account_occurrencesindices on the loader / CLI processing path, where they're never read.walk_descendants_oncewas the #1 allocation-count site in the profile. For everyACCOUNT/CURRENCYtoken it builds aSpanned<Account>/Spanned<Currency>(anAccount::new/Currency::newallocation) and does an O(depth) in-ERROR_NODEancestor walk. But these two indices are consumed solely by the LSP (rename / references / highlight) — confirmed by grep: zero consumers outsiderustledger-parser+rustledger-lsp. The loader /rledger check|querypipeline builds them and throws them away.Change
parse_without_occurrences(source)threadscollect_occurrences = falseintowalk_descendants_once, which then skips theACCOUNT/CURRENCYconstruction and their ancestor walks. Inline errors + top-level comments are still collected (the pipeline needs them).parse()is unchanged — the LSP and all 293 other call sites keep full behavior.Measured impact (10k-txn workload, dhat + cachegrind)
Largest heap and CPU win of the profiling series.
Safety
parse()semantics unchanged → LSP unaffected; the returnedParseResultdiffers fromparse()'s only in the two now-empty occurrence vectors.parse_without_occurrences_skips_indices_but_matches_directives) pins: occurrences empty, butdirectives/errors/optionsidentical toparse().cargo test -p rustledger-parser(280) +-p rustledger-loader(89) pass; parser+loader+lspcargo check+ clippy clean.Found via
The nightly
profilingdata branch — fourth optimization it surfaced.🤖 Generated with Claude Code