-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 memory and performance gap between parse
and parseAsync
#3446
Comments
Thanks for the effort you put into this benchmark! I'm broadly aware of this and am working on solutions in Zod 4. There are some very obvious performance in Zod's current parsing pipeline that unfortunately will require breaking changes to fix. I'll report back with updated performance numbers against this benchmark once Zod 4 is nearing beta. |
Great, that sounds very nice! |
Wonder if it would work to get rid of |
^I made a POC of not using Results using your benchmark @warflash : zod@3.23.4:
branch:
The reason sync/async are almost the same in the branch is that it doesn't extra wrap any promises. A more comprehensive benchmark would include stuff like async refines to see what the impact is |
Running
parseAsync
instead ofparse
seems to have massive differences in resource consumption for larger objects.I'd expect some overhead of async operations for sure, however in our production env. and in the benchmark as well the difference is 100x in time consumption and 10x in memory consumption.
Larger objects even OOM the entire node app with
parseAsync
whereasparse
hovers at around 300mb.The reproduction of a minimal bench setup can be found here: https://github.com/warflash/zod-async-perf
Tested on 2 machines with node 18 and 20.
Logs:
The text was updated successfully, but these errors were encountered: