r/javascript • u/gajus0 • Jun 11 '26
Compile Zod schemas into zero-overhead validators (2-74x faster)
https://github.com/gajus/zod-compiler
47
Upvotes
r/javascript • u/gajus0 • Jun 11 '26
6
u/Akkuma Jun 11 '26
How does this compare in performance to using https://github.com/sinclairzx81/typedriver ?
4
u/microbiont Jun 11 '26
Zod 4 uses JIT /
Function()constructors, so I'd be surprised if you're getting speedup from AOT with significantly more than two runs. Are you also including the hoisting speedup in the 2-74x number?I haven't looked at your code, but even if there were no speedup, AOT is nice because you don't have that first
Function()constructor call and you can run with a stricter CSP.2
u/name_was_taken Jun 11 '26
Neat, but I'm trying to imagine the form that needs 74x speed improvement to the validation. It's a pretty crazy form.
Even 2x speed improvement is probably imperceptible to the user for the vast majority of forms.
1
u/mattsowa Jun 11 '26
Would love the same for valibot
1
u/servermeta_net Jun 11 '26
Even better would be to write parsers with validation from Json schemas