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
Contributor

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.

@Zeragamba
Copy link
Contributor

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

@Zeragamba Zeragamba merged commit 9ea5a3d into faker-ruby:master Oct 26, 2020
@amatsuda amatsuda deleted the load_less_locales branch October 26, 2020 23:48
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
This was referenced Mar 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants