Performance improvement for array and hash#610
Open
mayur-kambariya wants to merge 2 commits intorails:mainfrom
Open
Performance improvement for array and hash#610mayur-kambariya wants to merge 2 commits intorails:mainfrom
mayur-kambariya wants to merge 2 commits intorails:mainfrom
Conversation
Member
|
Can you provide benchmark and results for those performance improvements? Otherwise we can't merge |
moberegger
reviewed
Jan 23, 2026
Comment on lines
+15
to
+17
| # Check cache without mutex for common case (reading) | ||
| cached_value = @cache[key] | ||
| return cached_value if cached_value |
moberegger
reviewed
Jan 23, 2026
Comment on lines
-366
to
+379
| BLANK == value | ||
| value == BLANK |
Contributor
There was a problem hiding this comment.
My benchmark shows that the original version is faster, at least when comparing against a Hash.
value = { a: 1, b: 2, c: 3 }
Benchmark.ips do |x|
x.report('value == BLANK') { value == BLANK }
x.report('BLANK == value') { BLANK == value }
x.compare!(order: :baseline)
endruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +YJIT +PRISM [arm64-darwin24]
Warming up --------------------------------------
value == BLANK 1.692M i/100ms
BLANK == value 2.332M i/100ms
Calculating -------------------------------------
value == BLANK 24.381M (± 2.0%) i/s (41.02 ns/i) - 123.504M in 5.067597s
BLANK == value 40.648M (± 2.0%) i/s (24.60 ns/i) - 205.219M in 5.050778s
Comparison:
value == BLANK: 24380939.0 i/s
BLANK == value: 40647529.7 i/s - 1.67x faster
moberegger
reviewed
Feb 5, 2026
Comment on lines
+353
to
+358
| if collection.respond_to?(:filter_map) | ||
| collection.filter_map do |element| | ||
| mapped_element = _scope{ yield element } | ||
| mapped_element unless mapped_element == BLANK | ||
| end | ||
| else |
Contributor
There was a problem hiding this comment.
According to my benchmark, this change results in a performance degradation. I propose an alternative in #612.
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.