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.
Similar rational to #54
A note about the implementation
Of note, I attempted to use both
.each_with_object
and.inject
instead of implementing something myself. But each had it's own problems that were either broken or sub-optimal:.each_with_object
The
.each_with_object
implementation looked something like this:Obviously this allows us to omit the
result = self
line above it, but this implementation just failed to function in some scenarios and I was unable to determine the cause..inject
The
.inject
implementation was similar to the above.each_with_object
implementation:While actually functioning as expected, and just making sure to end the block with a final call of
result
, the combination of having to do.each
,.with_index
, and.inject
to achieve having both a indexed loop and a resulting object actually caused some extra objects to becreated.
Being explicit here and avoiding the ruby convenience methods seemed to both prevent extraneous objects instantiation and provide the results expected.
Benchmarks
I used the existing benchmarks for #54 (an effort originating from ManageIQ/manageiq#15757) as a base, and applied these changes on top of them when doing the benchmarks to see the over all effect.
.inject
).inject
)Comparing the objects allocated by gem, we can see that
more_core_extensions
is the only one to change and improve between runs:Links
more_core_extensions
: Reduce memory usage of.store_path
#54