Commit 618bf38
committed
Use memoized I18n.locale_available? in Config.locale
I18n.locale_available? checks a memoized set of locales, unlike
I18n.available_locales which rebuilds its array on every call, so the
common case (the current I18n locale is available) no longer allocates.
Benchmark (Ruby 3.4.9, arm64-darwin25, benchmark-ips):
require 'benchmark/ips'
require 'faker'
Benchmark.ips do |x|
x.config(warmup: 1, time: 2)
x.report('Config.locale') { Faker::Config.locale }
end
Results:
main: Config.locale 178.877k (+/-16.1%) i/s
this commit: Config.locale 992.950k (+/- 2.5%) i/s (~5.5x)1 parent 9b07803 commit 618bf38
1 file changed
Lines changed: 4 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
29 | 32 | | |
30 | 33 | | |
| |||
0 commit comments