Avoid cloning in Array::filter_map_to (for map_each)#183
Merged
marmeladema merged 4 commits intoJul 8, 2026
Conversation
marmeladema
reviewed
Jul 8, 2026
| let mut write = 0; | ||
| for read in 0..vec.len() { | ||
| let elem = &mut vec[read]; | ||
| if let Some(elem) = func(std::mem::replace(elem, LhsValue::Bool(false))) { |
Collaborator
There was a problem hiding this comment.
At first glance, I am not convince by this change. Before/after seem equivalent? Before we would only allocate a vec for the borrowed case; which is done anyway in the new code further down.
The only thing that seems to be avoided in the new code is the mem::replace in the borrowed case. Is that really responsible for a substantial speedup?
Collaborator
Author
There was a problem hiding this comment.
The change is in the deleted line 166: slice.to_vec(), which clones & allocates, only to throw away the cloned/allocated LhsValues (often bytes) & using the Vec to store bools. It is better to pass a borrowed LhsValue & let the called function be optimised for borrowed cases.
utkarshgupta137
force-pushed
the
ugupta/perf/map_each
branch
from
July 8, 2026 10:30
5319c94 to
4de9a13
Compare
utkarshgupta137
force-pushed
the
ugupta/perf/map_each
branch
from
July 8, 2026 10:35
4de9a13 to
831413c
Compare
marmeladema
approved these changes
Jul 8, 2026
marmeladema
approved these changes
Jul 8, 2026
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.
No description provided.