Skip to content

Cache currency symbol regex to improve parse performance#193

Merged
yukideluxe merged 4 commits intoRubyMoney:mainfrom
pranavbabu:patch-1
Jul 23, 2025
Merged

Cache currency symbol regex to improve parse performance#193
yukideluxe merged 4 commits intoRubyMoney:mainfrom
pranavbabu:patch-1

Conversation

@pranavbabu
Copy link
Copy Markdown
Contributor

Cached the currency symbol regex in Parser to avoid recompiling it on every parse call, improving performance during repeated monetary parsing operations.

Benchmarking currency_symbol_regex creation...
                                user     system      total        real
Dynamic regex generation:   0.551297   0.001920   0.553217 (  0.553221)
Cached regex reuse:         0.003189   0.000083   0.003272 (  0.003271)

Comment thread lib/monetize/parser.rb Outdated
Co-authored-by: Sunny Ripert <sunny@sunfox.org>
Copy link
Copy Markdown
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just remove the method and just use the constant here?

match = input.match(currency_symbol_regex)
😊

@yukideluxe
Copy link
Copy Markdown
Member

also, I think the test failure is related 🙏🏻

Copy link
Copy Markdown
Member

@yukideluxe yukideluxe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@yukideluxe yukideluxe merged commit 549ace4 into RubyMoney:main Jul 23, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants