
I Made Zod 64x Faster by Compiling Schemas at Build Time
Zod v4 is fast. But what if you could skip schema traversal entirely? I built a compiler that turns your Zod schemas into plain JavaScript validation functions at build time — and it's 2–64x faster. The Problem: Runtime Schema Traversal Is Inherently Slow Zod is everywhere. With over 100 million weekly npm downloads, it's the de facto standard for runtime validation in TypeScript. The API is beautiful — you define a schema, and you get both runtime validation and static types for free. But that elegance has a cost. Every time you call .parse() , Zod walks the entire schema tree at runtime. It checks each node type, applies constraints, collects errors, and constructs the result. For a simple z.string() , the overhead is negligible. But for a nested object with arrays, unions, and dozens of fields? That tree walk adds up fast. // Every .parse() call traverses this entire tree — every time const UserSchema = z . object ({ id : z . string (). uuid (), name : z . string (). min ( 1 ). max
Continue reading on Dev.to JavaScript
Opens in a new tab




