Skip to content

Add Lazy loading config#3244

Merged
stefannibrasil merged 2 commits into
mainfrom
lazy-loading-beta
Apr 16, 2026
Merged

Add Lazy loading config#3244
stefannibrasil merged 2 commits into
mainfrom
lazy-loading-beta

Conversation

@stefannibrasil

Copy link
Copy Markdown
Contributor

Faker now lazy loads the generators. It means users will only pay for what they use. Faker loads more than 2.08x faster when enabling it.: https://github.com/faker-ruby/faker/blob/main/experiments/lazy_load.md

Lazy loading the generators is disabled by default. To enable it, choose one of the configuration options below:

1 - Set lazy load as a Faker Config

Faker::Config.lazy_loading = true

2 - Set lazy load as an environment variable

FAKER_LAZY_LOAD = 1

We hope you get to see the improvement by enabling lazy load.

Please report any issues!

thdaraujo and others added 2 commits April 14, 2026 14:22
Adds configuration option to enable/disable lazy loading
so it can be explicitly enabled during beta testing.
* Lazy load generators

To keep this change backwards compatible, we introduce
lazy loading as a config option.

We need to load main classes
first for nested generators such as 'music' and
when lazy loading is not enabled. 'internet/http'.

This will avoid the need for renaming these generators.

Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>

* Clean up skipped generators from determinism test

* Rename test file following conventions

* Run lazy loading smoke test in CI

* Check for true values when setting ENV['FAKER_LAZY_LOAD']

Covers the case of users setting the env using
truthy values.

* Better code for checking for ENV values

---------

Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>
@stefannibrasil stefannibrasil merged commit 7193b32 into main Apr 16, 2026
18 checks passed
@stefannibrasil stefannibrasil deleted the lazy-loading-beta branch April 16, 2026 18:02
@franzliedke

Copy link
Copy Markdown

@stefannibrasil This looks exciting, but how exactly does the config work? If I see things correctly, Faker::Config is defined in faker.rb, which I have to load in order to change configs.

But that file already eager loads all the other code, right?

require "faker"

Faker::Config.locale = :de
Faker::Config.lazy_loading = true

@franzliedke

Copy link
Copy Markdown

Ah, already reported in #3248.

@stefannibrasil

Copy link
Copy Markdown
Contributor Author

Hi @franzliedke thanks for reporting this! Yes, we are aware of the bug and are working on it. In the meantime, use the env var method.

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.

3 participants