Repository navigation
Reserve room for a whole vector in VecWriter with simd - #387
Open
emschwartz wants to merge 3 commits into
Open
emschwartz wants to merge 3 commits into
emschwartz wants to merge 3 commits into
Conversation
With the `simd` feature, `ArrayStore -= &ArrayStore` reserved `min(lhs.len(), rhs.len())` for its output, but a difference can hold up to `lhs.len()` values. The Vec grew to cover it, so results were correct. Reserve `lhs.len()`, as `Sub` already does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every caller reserves an upper bound for its output, so the `push` in `visit_scalar` never reallocates, but the compiler cannot see that. The scalar merge loops for `&`, `|`, `^` and `-` therefore carry a call to `grow_one` and reload the Vec's fields from the stack on each write. Asserting `len < capacity` before the push removes the call and lets the loops keep their state in registers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`visit_vector` appends all eight lanes and then truncates to the ones that matched, so a write near the end of the reserved space grows the Vec even though the output fits. Intersecting 500 values with a superset of 4000 reserves 500 and returns a Vec with capacity 1000, and `into_inner` does not shrink it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Stacked on #385: only the last commit is new.
With
simd,VecWriter::visit_vectorappends all eight lanes and then truncates to the ones that matched. A vector write within eight slots of the reserved capacity therefore grows the Vec even though the output fits, andinto_innerdoes not shrink it. Intersecting 500 values with a superset of 4000 reserves 500 and returns a Vec with capacity 1000.Reserving eight extra slots under
simdavoids the regrow. The added test fails without it. This is about memory, not speed: over 3 runs on the machines from #385, timings were within 1% of that PR.Authored with Claude (claude-opus-5-5).