Repository navigation
refactor(module): reuse one Faker instance per FakerCore in standalone functions - #4260
Closed
TheNetherWatcher wants to merge 1 commit into
Closed
TheNetherWatcher wants to merge 1 commit into
TheNetherWatcher wants to merge 1 commit into
Conversation
…e functions Standalone functions that resolve patterns via helpers.fake created a new Faker on every call. Reuse one instance per FakerCore instead; all state lives in the FakerCore, so the output is unchanged.
✅ Deploy Preview for fakerjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## next #4260 +/- ##
=======================================
Coverage 99.14% 99.14%
=======================================
Files 1179 1180 +1
Lines 3976 3983 +7
Branches 709 724 +15
=======================================
+ Hits 3942 3949 +7
Misses 29 29
Partials 5 5
🚀 New features to boost your workflow:
|
Member
|
Thanks for your interest in improving the performance of Faker. The fake method calls will be replaced before v11.0 releases using resolver functions. Which would render this PR's changes obsolete. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since #4033 (not released yet), 17 standalone functions that resolve a pattern through
helpers.fakebuild a newFakeron every call, e.g.fakePersonLastName,fakeLocationCity,fakeCompanyName,fakeInternetUserAgent. Building aFakersets up every module, so these calls, and the module methods that call them (faker.person.lastName()etc.), are now roughly 10-40x slower than in 10.6.0.This adds an internal
getFakerForCore(fakerCore)that keeps oneFakerperFakerCorein aWeakMap, and uses it in those 17 functions. The cached instance shares the core's randomizer, locale and config, so the output is unchanged for every seed. No snapshots changed. Seeded output ofnextand this branch matches across all 78 locales (20 methods that use these functions, 60 draws each).The helper only gets imported by files that already imported
Faker, so it adds no new import edges and doesn't conflict with #4220.µs per call (best of 5 runs of 20k calls), Node 24.12, Apple M4 Pro:
nextperson.lastName()person.fullName()person.jobTitle()location.city()location.streetAddress()company.name()commerce.productName()internet.userAgent()hacker.phrase()