-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
performance: remove unnecessary i18n locale reload #2723
performance: remove unnecessary i18n locale reload #2723
Conversation
I18n is reloaded whenever load_path are set, so an additional reload is not needed and only increases load time.
thanks for submitting this @codez! I think your suggestion makes sense. But we had so many problems related to this in the past that I would like to have a test to make sure there's no regression. |
I tested main and I tested your change and they both seem fine. But I couldn't really reproduce the original issue anymore, so not sure. Here's what I've tried: # frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'faker', :git => 'https://github.com/codez/faker.git', :branch => 'remove-unnecessary-i18n-reload', require: false
# gem 'faker', :git => 'https://github.com/faker-ruby/faker.git', :branch => 'main', require: false
gem "minitest"
end
require "minitest/autorun"
require "i18n"
class BugTest < Minitest::Test
def test_faker
refute I18n.backend.initialized?
assert require 'faker'
puts Faker::Name.name
assert Faker::Name.name
end
def test_faker_forking
refute I18n.backend.initialized?
pid = fork do
assert require 'faker'
assert Faker::Name.name
end
_, status = Process.waitpid2(pid)
assert status.success?, "Failed in forked process"
end
end Maybe someone has a better idea and is able to reproduce the original issue so we can know for sure. |
hi @codez Thanks for your contribution! Like @thdaraujo mentioned, it's hard to keep changing this without being sure if it will still work, or why it wasn't working in the first place. Could you please provide more reproduction steps and automated tests to help with the reproduction as well? Thanks! |
I added a test that loads faker in a subshell and asserts that the original issue now works. Because the reloading is actually done in the |
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.
Thanks for adding tests! Left a suggestion on how to handle the exit status.
87461cb
to
f566248
Compare
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.
CI is not passing
f566248
to
bfb9ee4
Compare
I adjusted the test, it should hopefully pass now. |
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.
LGTM, thank you for adding tests!
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.
LGTM
Summary
I18n is reloaded whenever load_path is set, so an additional reload is not needed and only increases load time (because all locale files are reloaded twice 😞).
See https://github.com/ruby-i18n/i18n/blob/b4cd00d73234e369d713eb2607c729765bb3ec06/lib/i18n/config.rb#L135
Other Information
The steps described in the original issue that introduced the reload now work as expected, even without the reload.