perf(deque): avoid unnecessary allocations in extract_if, filter, to_array#3331
Closed
bobzhang wants to merge 1 commit into
Closed
perf(deque): avoid unnecessary allocations in extract_if, filter, to_array#3331bobzhang wants to merge 1 commit into
bobzhang wants to merge 1 commit into
Conversation
Collaborator
Pull Request Test Coverage Report for Build 3152Details
💛 - Coveralls |
3a37ee8 to
21170ac
Compare
…array - extract_if/filter: pre-allocate result deque with capacity=self.len instead of starting from capacity 0, avoiding repeated reallocations and copies during common "keep most elements" patterns - to_array: use Array::new(capacity=len) + push instead of Array::make(len, self[0]) + overwrite, avoiding the redundant initial fill with self[0] that doubles work for expensive-to-copy types Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
21170ac to
e740a8c
Compare
Contributor
Author
|
closed since this is not necessarily good, it may be super wasteful, if for 1,000,000 elements only 1 gets extracted |
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
capacity=self.leninstead of starting from capacity 0.Array::new(capacity=len)+pushinstead ofArray::make(len, self[0])+ overwrite, avoiding redundant initial fill.Test plan
moon test -p moonbitlang/core/deque— all 232 tests pass🤖 Generated with Claude Code