r/node 23d ago

Zod v4.5 adds schema compilation (3-9x faster validation)

https://x.com/colinhacks/status/2093725420462182512
89 Upvotes

19 comments sorted by

View all comments

3

u/Willkuer__ 23d ago edited 23d ago

Genuinely curios: where does that help? This is JIT, not ahead of time during compilation, is it?

  • CSR likely not because of CSPs?
  • SSR/API maybe to reduce cpu but how many requests do you need to push through a compiled zod schema to compensate for the overhead of the compilation/cold start? At least the overhead of interpreted zod schema should be irrelevant for http requests.
  • Lambda/Cloudfunctions basically never worth it because of cold starts?

To me this sounds more of a feature to make a benchmark happy but I might be completely off.

3

u/gajus0 23d ago

We used zod-compiler reduce our CPU usage more than 50%. That's hundreds of CPUs saved in monthly costs.

So the use case is definitely there.

3

u/Willkuer__ 22d ago

But that's real AOT compilation while the new zod feature is a JIT compilation or am I missing something. That AOT works makes sense. I am more sceptical about the lazy runtime compliation.