ruby-i18n / i18n

Internationalization (i18n) library for Ruby
MIT License
986 stars 411 forks source link

No longer rely on refinements for Hash utility methods. #573

Closed casperisfine closed 3 years ago

casperisfine commented 3 years ago

Refinements have a very significant performance overhead. The simple fact of refining a method, even if the refinement is never used will make calls to that method 40% slower.

On rarely called methods in doesn't matter that much, but I18n refine some popular Active Support methods, so any project including the I18n gem suffer from a significant performance penalty.

See this benchmark for more details: https://gist.github.com/casperisfine/1c46f05cccfa945cd156f445f0d3d6fa

In the end these refinements are easily replace by simple module functions taking one extra argument.

casperisfine commented 3 years ago

@radar any chance this PR could be considered?

radar commented 3 years ago

Thank you @casperisfine, this looks great.

mpantel commented 2 years ago

There is still some issue because i18n/core/hash still gets called in: lib/i18n/backend/chain.rb and lib/i18n/backend/gettext.rb and rails fails to load: `require': cannot load such file -- i18n/core_ext/hash (LoadError)

while Utils is correclty referenced in those files...