perf: skip redundant downcase in Currency.find! on cache hits#521
Open
perf: skip redundant downcase in Currency.find! on cache hits#521
downcase in Currency.find! on cache hits#521Conversation
Currency mappings in #value_to_currency
elfassy
reviewed
Mar 12, 2026
Contributor
There was a problem hiding this comment.
I think we're better off improving the find! method (already cached) than adding another layer of caching. Ex #519 (comment). The only difference is that this PR is not downcasing the currency string. This means the cached hash could be double the size if people use both lower and upper case, making each search slower and use more memory. You can account for the larger hash by looping through every currency in both upcase and lowercase a few times in your benchmark
1391c5d to
7eb9050
Compare
fdce13e to
ca934a4
Compare
ca934a4 to
3f417f5
Compare
Currency mappings in #value_to_currencydowncase in Currency.find! on cache hits
Base automatically changed from
cribbles/perf-skip-redundant-currency-resolution
to
main
March 16, 2026 14:42
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
Optimize
Currency.find!(aliased fromCurrency.new) to skipto_s.downcaseon cache hits. On the first resolution of a currency string (e.g."USD"), the result is stored under both the original-case and downcased keys in@@loaded_currencies. Subsequent lookups hit the fast path immediately without allocating a downcased string or checking the mutex.Stacks on #520.
Benchmark (2M iterations of
Money.new)main
#520 (base branch)
This branch
Summary