Skip to report

A compiler connects Zod’s entry point to Core

Trace the new schema compiler into its opt-in entry point, Classic and Mini APIs, and downstream consumers.

colinhacks/zod #6085 · PR by colinhacks · Merged

colinhacks/zod 9f0a3d81..60496a09

base and head as given

  • Zod now offers ahead-of-time schema compilation.
  • Classic and mini APIs now expose schema compilation.
  • Compilation benchmarks were added to the benchmark suite.
  • Compilation fuzzing was added to developer tooling.
files changed
54
in a component
34
lines in components
5,846
components
6
public routes changed
0
schema statements
0
new dependencies
0
excluded by role
20
Based on 11 of 34 eligible changed files

Ahead-of-time schema compilation

Added
Before
did not exist
After
Schemas can use generated fast paths

The explicit API returns generated validators for supported synchronous schemas and reports unsupported or asynchronous ones. An opt-in side-effect import applies compilation lazily and keeps unsupported schemas on runtime parsing.

In favour

  • In favour: Unsupported child schemas remain runtime islands within compiled parents
  • In favour: Global mode restores unsupported schemas to runtime parsing

Against

  • Against: Explicit compilation depends on dynamic function construction in CSP-restricted environments

Compilation validation tooling

Added
Before
did not exist
After
Fuzzing and benchmarks cover compilation

Maintainers can compare generated and runtime parser results using seeded randomized schemas, and benchmark compiled validation across representative schema shapes and ArkType.

In favour

  • In favour: Seeds make differential-parser failures reproducible
  • In favour: Benchmark correctness gates reject divergent compiled output

The model found nothing to weigh against this.

Files changed in 6 components. Dependencies shown: 1 new, 5 unchanged
unchanged · 5new · 1

1 new dependency between components — Zod Source → Core Library

What else could behave differently

11 components · 125 files

These components import changed code, directly or through other files. A traced dependency is a place to review, not a confirmed runtime failure. Some paths stopped at heavily imported files; inspect those consumers separately.

Reached 3

ComponentSymbolCited atFilesReached by
Core Librarypackages/zod/src/v4/core/Body changed 1 of 9 changed symbols reaching itpackages/zod/src/v4/core/core.ts:24-110176 direct · 9 at two steps · 2 at three steps
Trace path

Shortest component path from the changed symbol:

  1. Core Library

Later steps follow file imports; they do not prove this symbol is called.

packages/zod/src/v4/locales/Signature changed 1 of 2 changed symbols reaching itpackages/zod/src/v4/core/core.ts:157-17161none direct · 58 at two steps · 3 at three steps
Trace path

Shortest component path from the changed symbol:

  1. Core Library
  2. packages/zod/src/v4/locales/

Later steps follow file imports; they do not prove this symbol is called.

Zod Sourcepackages/zod/src/Added 1 of 14 changed symbols reaching itpackages/zod/src/v4/core/compile.ts:91-13921 direct · 1 at two steps
Trace path

Shortest component path from the changed symbol:

  1. Core Library
  2. Zod Source

Later steps follow file imports; they do not prove this symbol is called.

Held back 3

ComponentFilesReached byResolution
scripts/1none direct · 1 at three stepsprecise
packages/bench/19none direct · 1 at three steps · 18 at four stepsprecise
packages/zod/src/locales/1none direct · 1 at four stepsprecise

Ranked lower 5

ComponentFilesReached by
packages/zod/src/v4/classic/123 direct · 9 at two steps
packages/zod/src/v4/mini/93 direct · 5 at two steps · 1 at three steps
packages/zod/src/mini/1none direct · 1 at two steps
packages/zod/src/v4-mini/1none direct · 1 at two steps
packages/zod/src/v4/1none direct · 1 at two steps

Not traced past a hub 3

SymbolHub fileImported by
packages/zod/src/v4/core/core.ts:$constructorpackages/zod/src/v4/core/checks.ts65
packages/zod/src/v4/core/core.ts:$constructorpackages/zod/src/v4/core/errors.ts72
packages/zod/src/v4/core/core.ts:$constructorpackages/zod/src/v4/core/util.ts79

Statements 3

The $constructor body changed and reached 17 files in the core library. 692
packages/zod/src/v4/core/core.ts:24-110
The $ZodConfig signature changed and reached 61 files in locales. 583
packages/zod/src/v4/core/core.ts:157-171
compile was added and reached 2 files in the Zod source. 11
packages/zod/src/v4/core/compile.ts:91-139

25 reached files belong to no component — tests, docs and config.

Routes, schema, dependencies

No public URL, no migration and no new package.

Inspect components, files and symbols

Component

Build ScriptsModified
scripts/

2 files · 489 lines

Ahead-of-time schema compilation, added

Core LibraryModified
packages/zod/src/v4/core/

7 files · 2,145 lines

5 dependents

The core export surface added 12 names: CONSTANT_CATCH, INVALID, ZodCompileAsyncError, ZodCompileUnsupportedError, compile, compileFastpass, constantCatch, isRecursiveSchema, isValidCIDRv6, isValidIPv6, mergeValues, and parseValidURL.

Ahead-of-time schema compilation, added

Benchmark SuiteModified
packages/bench/

20 files · 3,149 lines

The benchmark export surface added SINK and sink.

Compilation validation tooling, added

Zod SourceModified
packages/zod/src/

1 file · 53 lines

1 dependent

Ahead-of-time schema compilation, added

Classic APIModified
packages/zod/src/v4/classic/

2 files · 5 lines

2 dependents

The classic API export surface added ZodCompileAsyncError, ZodCompileUnsupportedError, and compile.

Ahead-of-time schema compilation, added

Mini APIModified
packages/zod/src/v4/mini/

2 files · 5 lines

2 dependents

The mini API export surface added ZodCompileAsyncError, ZodCompileUnsupportedError, and compile.

Ahead-of-time schema compilation, added

File

Build Scriptsscripts/
scripts/compile-fuzz.ts

+439 −0

Ahead-of-time schema compilation, added

Build Scriptsscripts/
scripts/enable-compile.ts

+50 −0

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/compile.ts

+2,010 −0

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/schemas.ts

+85 −17

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/core.ts

+10 −0

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/memoizer.ts

+10 −0

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/util.ts

+10 −0

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/api.ts

+1 −1

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/index.ts

+1 −0

Ahead-of-time schema compilation, added

Zod Sourcepackages/zod/src/
packages/zod/src/compile.ts

+53 −0

Ahead-of-time schema compilation, added

Classic APIpackages/zod/src/v4/classic/
packages/zod/src/v4/classic/external.ts

+3 −0

Ahead-of-time schema compilation, added

Classic APIpackages/zod/src/v4/classic/
packages/zod/src/v4/classic/schemas.ts

+1 −1

Ahead-of-time schema compilation, added

Mini APIpackages/zod/src/v4/mini/
packages/zod/src/v4/mini/external.ts

+3 −0

Ahead-of-time schema compilation, added

Mini APIpackages/zod/src/v4/mini/
packages/zod/src/v4/mini/schemas.ts

+1 −1

Ahead-of-time schema compilation, added

Benchmark Suitepackages/bench/
packages/bench/compile-vs-arktype.ts

+477 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-matrix.ts

+449 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-passthrough.ts

+310 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-output.ts

+274 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-object-build.ts

+235 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-validate-vs-parse.ts

+194 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-codec-direction.ts

+154 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-wrapper-cost.ts

+150 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/bench-invalid.ts

+148 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-array-build.ts

+122 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-base64-inline-vs-hoist.ts

+120 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-helper-scope.ts

+109 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/arktype-morph-test.ts

+72 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-tuple.ts

+67 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile.ts

+66 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-startswith.ts

+56 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-overwrite.ts

+53 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-endswith.ts

+49 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-includes.ts

+42 −0

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/metabench.ts

+1 −1

Compilation validation tooling, added

Function

imports what changeddownstream of it, one mark per step

ZodCompileAsyncError()packages/zod/src/v4/core/compile.ts

reaches 6 components

ZodCompileAsyncError was added and reached 12 files in the classic API. 39
packages/zod/src/v4/core/compile.ts:34-39
ZodCompileAsyncError was added and reached 9 files in the mini API. 351
packages/zod/src/v4/core/compile.ts:34-39
ZodCompileAsyncError was added and reached 1 file in the mini source. 1
packages/zod/src/v4/core/compile.ts:34-39
ZodCompileAsyncError was added and reached 1 file in v4-mini. 1
packages/zod/src/v4/core/compile.ts:34-39
ZodCompileAsyncError was added and reached 1 file in v4. 1
packages/zod/src/v4/core/compile.ts:34-39
ZodCompileAsyncError was added and reached 19 files in the benchmark suite. 118
packages/zod/src/v4/core/compile.ts:34-39

Ahead-of-time schema compilation, added

$constructor()packages/zod/src/v4/core/core.ts

reaches 3 components

Analysis stopped tracing the $constructor body change at checks.ts after 1 hop to avoid 65 importers.
packages/zod/src/v4/core/core.ts:24-110
Analysis stopped tracing the $constructor body change at errors.ts after 1 hop to avoid 72 importers.
packages/zod/src/v4/core/core.ts:24-110
Analysis stopped tracing the $constructor body change at util.ts after 2 hops to avoid 79 importers.
packages/zod/src/v4/core/core.ts:24-110

Ahead-of-time schema compilation, added

Diff

Build Scriptsscripts/
scripts/compile-fuzz.ts

1–439

Ahead-of-time schema compilation, added

Build Scriptsscripts/
scripts/enable-compile.ts

1–50

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/compile.ts

1–2010

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/schemas.ts

502–556, 879–888, 896–896 and 3 more spans

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/core.ts

95–97, 164–170

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/memoizer.ts

79–88

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/util.ts

1112–1121

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/api.ts

1539–1539

Ahead-of-time schema compilation, added

Core Librarypackages/zod/src/v4/core/
packages/zod/src/v4/core/index.ts

13–13

Ahead-of-time schema compilation, added

Zod Sourcepackages/zod/src/
packages/zod/src/compile.ts

1–53

Ahead-of-time schema compilation, added

Classic APIpackages/zod/src/v4/classic/
packages/zod/src/v4/classic/external.ts

27–29

Ahead-of-time schema compilation, added

Classic APIpackages/zod/src/v4/classic/
packages/zod/src/v4/classic/schemas.ts

2448–2448

Ahead-of-time schema compilation, added

Mini APIpackages/zod/src/v4/mini/
packages/zod/src/v4/mini/external.ts

26–28

Ahead-of-time schema compilation, added

Mini APIpackages/zod/src/v4/mini/
packages/zod/src/v4/mini/schemas.ts

1637–1637

Ahead-of-time schema compilation, added

Benchmark Suitepackages/bench/
packages/bench/compile-vs-arktype.ts

1–477

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-matrix.ts

1–449

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-passthrough.ts

1–310

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-output.ts

1–274

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-object-build.ts

1–235

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-validate-vs-parse.ts

1–194

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-codec-direction.ts

1–154

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-wrapper-cost.ts

1–150

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/bench-invalid.ts

1–148

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-array-build.ts

1–122

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-base64-inline-vs-hoist.ts

1–120

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-helper-scope.ts

1–109

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/arktype-morph-test.ts

1–72

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-tuple.ts

1–67

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile.ts

1–66

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-startswith.ts

1–56

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-overwrite.ts

1–53

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-endswith.ts

1–49

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/compile-includes.ts

1–42

Compilation validation tooling, added

Benchmark Suitepackages/bench/
packages/bench/metabench.ts

11–11

Compilation validation tooling, added

Analysis scope

669 → 6
  1. 669
    files at head
  2. 32
    components
  3. 6
    changed by this change

Where the new files landed

23 new files
New fileBelongs toUsed byCallsServes
scripts/2 new files
Build Scriptsbase frame
nothing in the existing application
Core Library
packages/zod/src/v4/core/compile.ts
Core Librarybase frame
Zod SourceClassic APIMini API
nothing outside its own component
packages/bench/19 new files
Benchmark Suitebase frame
nothing in the existing applicationnothing outside its own component
packages/zod/src/compile.ts
Zod Sourcebase frame
Core Library
./compile

11 added files carry no component — 7 test, 3 docs, 1 config.

6components changed
5reached, not changed
0components added/removed
1dependencies added between components
0dependencies removed between components
0files moved to another path

54 files changed, 24 claims stated. 11 components reached in total.

naming: “model

narrative: “model

analyzer 0.1.0, config v1.9.0-phase8

Every line above is derived from 9f0a3d81..60496a09 and nothing else.