Schema performance? Zod, Typebox & Valibot

by Simeon Petrov

Thumbnail for Schema performance? Zod, Typebox & Valibot
  • NOTES
  • RANDOM

This is a personal note from a quick and shallow research. I keep these notes around so I don’t have 20k open tabs “for later”. Continue reading on your own risk 🚸

TL:DR

  • In large TS code spaces Zod (maybe?) will slow down the overall DX
  • Typebox seems quite faster than Zod, so it’s a possible and valid alternative?
  • Libraries like TypeSchema and Valibot are pretty interesting and can help with faster parsing and validating of schemas
  • Zod's performance is okay at the start, but when you start using methods like .extend/.pick/.omit (and so on) the performance regresses in the order of a magnitude.

Eh … what?

I have a small test app built with Bun and Elysia and there they’re using TypeBox and fro this github issue for Zod support I fell into a small wormhole for Zod and its potential issues. Here are some interesting and potentially important links for the future

Runtime type benchmarks

Why is my TypeScript intellisense 

You'll need to enable strict in your tsconfig.json:

"compilerOptions": {
    ...
    "strict": true
}

Issues with slow codebases

What I learned is that Zod's performance is okay at the start, but when you start using methods like .extend/.pick/.omit (and so on) the performance regresses in the order of a magnitude.