Capítulo 60 de 61
Zod 4 was a from-scratch redesign driven by design limitations that couldn't be fixed without breaking changes; the payoff is measured in double-digit parsing speedups, a 100x reduction in TypeScript compiler instantiations for common patterns, and roughly half the core bundle size.
.extend() calls dropped from >25,000 tsc type instantiations under Zod 3 to ~175 under Zod 4 — roughly a 100x reduction rooted in simplified generics on ZodObject and related classes. A repeated .extend()/.omit() chain that took ~4000ms to compile (and could trigger a "possibly infinite" type error) in Zod 3 compiles in ~400ms under Zod 4.z.boolean() script bundles to roughly 5.36kb (gzip) under Zod 4 versus 12.47kb under Zod 3 — about a 2.3x reduction, achieved before Zod Mini's further tree-shaking gains.zod/v4/core as a foundation: extracting shared logic into a core sub-package (needed to support Zod Mini) turned out to double as a stable substrate other libraries can build directly on top of.| Metric | Zod 3 | Zod 4 | Improvement |
|---|---|---|---|
z.string().parse | 363 µs/iter | ~24.7 µs/iter | ~14.7x |
z.array() parsing | 147 µs/iter | ~19.8 µs/iter | ~7.4x |
z.object() safeParse (Moltar bench) | 805 µs/iter | 124 µs/iter | ~6.5x |
tsc instantiations (sample object w/ .extend()) | >25,000 | ~175 | ~100x fewer |
Chained .extend()/.omit() compile time | ~4000ms | ~400ms | ~10x |
Core bundle size (z.boolean() script, gzip) | 12.47kb | 5.36kb | ~2.3x smaller |
.extend()-ed schemas that were borderline unusable under Zod 3's compiler cost are now comfortably fast.zod/v4/core wasn't originally planned as a public building block; it emerged from Zod Mini's requirements and became a deliberate platform for other libraries.