Why Is Zod v4 Fast — and Where Is Its Ceiling?
Why Is Zod v4 Fast — and Where Is Its Ceiling? Zod v4 is faster than v3. But almost nobody knows why. It's not just a cleaner codebase or smaller bundle — Zod v4 has a JIT-like code generator that ...

Source: DEV Community
Why Is Zod v4 Fast — and Where Is Its Ceiling? Zod v4 is faster than v3. But almost nobody knows why. It's not just a cleaner codebase or smaller bundle — Zod v4 has a JIT-like code generator that builds specialized validation functions at runtime using new Function(). It's hidden inside a class called $ZodObjectJIT, and unless you read the source, you'd never know it was there. I read the internals to understand how v4's performance works, benchmarked every schema type, and used what I learned to build an AOT compiler that extends the same idea to build time. Here's everything I found. What the benchmarks show: v4's JIT targets object schemas — delivering 1.3-4.5x over v3 for objects and recursive structures For other types (primitives with checks, collections), v4 traded raw throughput for a richer architecture (better errors, async support, modular checks) AOT compilation extends the JIT principle to all schema types: 3-60x faster than v4 Zod v3: The Interpreter Model Every time you