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

HUGE performance issues when using zod mock data (faker js) #208

Open
DawidWraga opened this issue Jun 21, 2024 · 1 comment
Open

HUGE performance issues when using zod mock data (faker js) #208

DawidWraga opened this issue Jun 21, 2024 · 1 comment

Comments

@DawidWraga
Copy link

For a while now my next.js app has been running incredibly slowly causing me a lot of frustration both in development and production.

I used next bundle analyzer to investigate this and found that faker-js was causing this.

image

I believe this is likely due to the imports not being localized properly inside the zod-mock package

(see https://fakerjs.dev/guide/localization.html#individual-localized-packages)

I have tried:

  • Added @faker-js/faker and @anatine/zod-mock to next.config.js transpilePackages array and optimizePackageImports
  • Changed zod mock dependency to run only in dev mode for testing

Unfortunately this did not help so for now I am uninstalling @anatine/zod-mock

Please let me know if there is any other info I can provide to help solve this issue

@Brian-McBride
Copy link
Contributor

This is a good point.
So the mocking app here goes through every function name inside Faker. So it does load up everything in faker.
It was meant to be a testing tool

I don't even think this should slow down a back-end service. It will raise the memory footprint a bit, but Faker isn't that huge.

What I see is that you are using it on the front end. I wouldn't even recommend using Faker there, to be honest. For anything you need to use, consider using Faker directly and only import the modules you need.

If you are using the new server side components and you are mocking on the back end and this is ending up in your bundled front end - I'd say this is an import issue around NextJS. I was a developer during the height of the PHP days, so I am a bit wary of mixing server and client code in a single file—separation of concerns and all that.

However, you are correct in your overall assessment. This package was always meant to be a shortcut helper for fast mocking, mainly in a testing environment. The nature of the tool should just keep up with faker updates in general based on the way it works. In order to be able to fake every possible type, you have to import all of Faker.

Plus, it walks through a zod object and then searches through every Faker function until it finds one that might match. There is no attempt at a fast search there either as that is not the target. I suppose that could be improved to add some slight performance increase.

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

No branches or pull requests

2 participants