Open
Conversation
moberegger
commented
Feb 5, 2026
| _scope{ yield element } | ||
| end - [BLANK] | ||
| end | ||
| collection.delete(BLANK) |
Contributor
Author
There was a problem hiding this comment.
Safe to mutate because the result of the map is local to the method. The input remains unaffected.
Contributor
Author
e2f3615 to
8032953
Compare
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.
Optimizes
_map_collection. This PR is somewhat inspired by work proposed in #610 wherefilter_mapwould be used for Ruby 2.7+.My benchmarks for this show that this implementation was 1.61x slower – which was surprising – but it got me curious to see if there were any gains to be made here. I tried one other approach to save on a memory allocation for
[BLANK]:but the proposed optimization performed the best both in terms of latency and memory. It saves on two intermediary array allocations, which I believe is where the 1.14x perf improvement comes from. The benchmarks below are directly against
_map_collection(note: I made the method non-private to quickly profile it)A simple benchmark against
array!shows an improvement, too. I made this as simple as possible to exercise the changes in_map_collectionas much as possible.For more complex templates, I would expect the gains to be diluted, but figured it was worth doing given that the implementation change is small and isolated.