-
-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve performance on enforce_available_locales! #249
Improve performance on enforce_available_locales! #249
Conversation
@@ -41,10 +41,18 @@ def available_locales | |||
@@available_locales || backend.available_locales | |||
end | |||
|
|||
def available_locales_set | |||
@@available_locales_set ||= available_locales.inject(Set.new) do |set, locale| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to trade off space for performance in here, So I am adding 2 entries for each locale. (which should be super small anyways). Thus, we dont need to cast to string when looking up.
Cache the available_locales in a local Set, so we can lookup, and check for inclusions faster. [fixes ruby-i18n#230]
https://gist.github.com/arthurnn/10031665 gist to check the benchmark regression, and fix. |
IPS results: before the regression:(version 0.6.5) Calculating -------------------------------------
6809 i/100ms
-------------------------------------------------
77460.3 (±3.4%) i/s - 388113 in 5.017347s after the regression:(version 0.6.8) Calculating -------------------------------------
3484 i/100ms
-------------------------------------------------
37268.7 (±3.4%) i/s - 188136 in 5.054946s after this PR applied: Calculating -------------------------------------
6168 i/100ms
-------------------------------------------------
69042.9 (±3.3%) i/s - 345408 in 5.008701s |
The validity of config.locale is inforced in Config#locale=. Related ruby-i18n#230 and ruby-i18n#249.
The validity of config.locale is inforced in Config#locale=. Related ruby-i18n#230 and ruby-i18n#249.
Improve performance on enforce_available_locales!
Thanks @arthurnn ❤️ |
The validity of config.locale is inforced in Config#locale=. Related ruby-i18n#230 and ruby-i18n#249.
The validity of config.locale is inforced in Config#locale=. Related ruby-i18n#230 and ruby-i18n#249.
The validity of config.locale is inforced in Config#locale=. Related ruby-i18n#230 and ruby-i18n#249.
Cache the available_locales in a local Set, so we can lookup, and check for inclusions faster.
[fixes #230]
review @carlosantoniodasilva