F-021: perf(services): stream whitespace-stripped comparison via Iterator::eq#24
Open
Sephyi wants to merge 1 commit intodevelopmentfrom
Open
F-021: perf(services): stream whitespace-stripped comparison via Iterator::eq#24Sephyi wants to merge 1 commit intodevelopmentfrom
Sephyi wants to merge 1 commit intodevelopmentfrom
Conversation
Three functions compared two strings with whitespace stripped by first collecting both into full `String` allocations, then comparing equality. Replace each with a streaming `Iterator::eq()` over filtered char iterators. This drops two heap allocations per call and short-circuits on the first differing character, which is the hot path when bodies actually differ. Affected sites: - ContextBuilder::classify_span_change (src/services/context.rs) - ContextBuilder::classify_span_change_rich (src/services/context.rs) - AstDiffer::bodies_semantically_equal (src/services/differ.rs) Behaviour is identical: `Iterator::eq` compares element-by-element and returns true iff both iterators yield the same sequence of chars. Existing tests (context, analyzer, languages suites) cover the semantic-classification paths and continue to pass. Closes audit entry F-021 from #3.
There was a problem hiding this comment.
Pull request overview
This PR addresses audit finding F-021 by optimizing whitespace-stripped comparisons to avoid intermediate String allocations and enable early-exit on the first mismatch.
Changes:
- Switch
AstDiffer::bodies_semantically_equalto stream filteredchariterators and compare viaIterator::eq. - Switch
ContextBuilder::{classify_span_change, classify_span_change_rich}to compare non-whitespace character streams viaIterator::eqinstead of allocating full strings.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/services/differ.rs | Removes allocation in body semantic equality check by streaming chars().filter(...).eq(...). |
| src/services/context.rs | Removes allocations in span whitespace-only detection by streaming filtered char iterators into Iterator::eq. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
perf(services): stream whitespace-stripped comparison via Iterator::eq.
Audit context
Closes audit entry F-021 from #3.
Verification
cargo fmt --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-targets