The Wayback Machine - https://web.archive.org/web/20201218090717/https://github.com/faker-ruby/faker/pull/2169
Skip to content
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

An attempt to load only necessary locales on the fly #2169

Merged
merged 2 commits into from Oct 26, 2020

Conversation

@amatsuda
Copy link
Member

@amatsuda amatsuda commented Oct 20, 2020

Issue#

No-Story

Description:

This patch attempts not to always load all bundled locale files.

Motivation:

Faker bundles so many I18n resources for various locales in the gem package, but indeed our real-world applications do not usually use all these locales. In my case, number of locales that we use in our tests are usually one or two.
That means, most of locales that Faker loads are consuming our time and memory per each test run although we never use them.
It'd be nicer if Faker loads the YAML files only for "the locales that we would use" i.e. available_locales.

Strategy:

Before this patch, Faker was telling I18n to load all bundled locale files at the very top level.
Instead, this patch suggests to load the ones that correspond to I18n.available_locales (note that the implementation is based on the assumption that each YAML file has the name of the locale that it contains).

In consideration of the case where I18n.available_locales value is not yet configured when the ruby process loads this library but being configured somewhere in the application initialization process, this patch tries to postpone loading YAML files as late as possible.
As a side effect, starting up a ruby process that bundles Faker but does not use Faker would become faster and less memory-consuming.

Note:

This PR would conflict with my previous PR #2167 but of course I'm happy to rebase whichever one.

@amatsuda amatsuda force-pushed the amatsuda:load_less_locales branch from 74d3aa9 to 1a303c0 Oct 20, 2020
@Zeragamba
Copy link
Contributor

@Zeragamba Zeragamba commented Oct 26, 2020

changes look good to me, and the tests are passing. Thanks!

@Zeragamba Zeragamba merged commit 9ea5a3d into faker-ruby:master Oct 26, 2020
6 checks passed
6 checks passed
Rubocop
Details
Ruby 2.5
Details
Ruby 2.6
Details
Ruby 2.7
Details
Ruby head
Details
Ruby truffleruby-head
Details
@amatsuda amatsuda deleted the amatsuda:load_less_locales branch Oct 26, 2020
vbrazo added a commit that referenced this pull request Nov 25, 2020
vbrazo added a commit that referenced this pull request Nov 25, 2020
* Rollback PR #2169

* Add changelog

* Bump version to 2.15.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants
You can’t perform that action at this time.