Repository navigation
perf(returns): compute all groups' self-containment in one transaction pass - #1845
Merged
Merged
Conversation
…n pass The --by-group self-containment warning check called first_shared_inscope_account once per group, each re-walking the whole directive stream — O(groups × txns) stream passes (classify only, no booking). Replace it with shared_inscope_accounts, which resolves every group's first shared in-scope account in ONE pass over the transactions (per-group cursors with an early-exit once a group resolves). The per-group first_shared_inscope_account is kept as the #[cfg(test)] reference oracle; shared_inscope_accounts_matches_per_group pins the batch == per-group across a pooled-cash fixture (two non-self-contained groups + one self-contained). Warning text and order are unchanged; the self-contained/overlap integration tests pass. Closes #1832.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes the report returns --by-group self-containment warning by replacing the per-group full directive-stream rescan with a batched scan that determines each group’s first shared in-scope account in a single pass over the transaction directives. This fits into the broader returns-reporting performance work by removing an avoidable N× multiplier when many groups are present.
Changes:
- Replaced per-group
first_shared_inscope_accountscans with a batchedshared_inscope_accountstransaction pass to resolve all groups’ warnings together. - Kept the original per-group implementation as a
#[cfg(test)]reference oracle. - Added a drift-guard test asserting the batched results match the per-group oracle per scope.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
📊 Benchmark Results
vs main branch (2026-07-21)
What do these numbers mean?
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Deep review noted the fixture did not exercise the order-sensitive path. Add a Mixed group whose FIRST touching transaction is self-contained (funded from an outside bank) so it must resolve at a LATER transaction that shares pooled cash; that resolving txn has two qualifying postings, pinning first-match selection. Both paths a future batch-vs-reference divergence could break are now covered. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
Copilot review: once unresolved hits 0 mid-transaction, the remaining groups are already resolved, so break the inner loop rather than skipping them one by one. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
…e_accounts Copilot review: the group loop scanned txn.postings twice (any() for touches, then find() for the shared account). Collapse to a single pass that tracks both, with identical semantics (first-match posting order, resolve only when the group is touched). Drift guard against the per-group reference still holds. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_013gJH7uBBF9Xw9et9QFRcsU
16 tasks
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.
What
The final
#1832item. The--by-groupself-containment warning check calledfirst_shared_inscope_accountonce per group, each re-walking the whole directive stream —O(groups × transactions)stream passes (classification only, no booking). Replaces it withshared_inscope_accounts, which resolves every group's first shared in-scope account in one pass over the transactions (per-group cursors, with an early exit once a group resolves).Correctness
Warning text and order are unchanged — this only reorders the scan. The per-group
first_shared_inscope_accountis kept as a#[cfg(test)]reference oracle, andshared_inscope_accounts_matches_per_grouppins batch == per-group on a pooled-cash fixture (two non-self-contained groups sharingAssets:Broker:Cash+ one self-contained group funded from outside the scope). The existing self-contained / prefix-overlap integration tests (which assert the exact stderr warnings) pass unchanged.Scope
Closes #1832 — with this, the whole returns-perf arc is done:
twrcompute_returnsentry point--by-groupscopesPart of #1814.
🤖 Generated with Claude Code