Repository navigation
Description
Background
I use Effect Schema to validate data at storage and API boundaries. Ajv is the standard, well-maintained JSON Schema validator and the natural point of comparison. I benchmarked the two because a performance gap in this layer would affect a lot of applications, even if most of them would never notice it in day-to-day use. Effect targets size and speed, so I think a gap of this size is worth understanding and reducing where that can be done without changing what validation means.
What I measured
I started with a representative set of record-like schemas, which I have not included here. Against Ajv, Effect was roughly 4.7x slower on the valid path and roughly 57x slower on the error path. The synthetic shapes I use for the reproducible benchmark are simpler, so they show smaller gaps: about 2.7x on a boolean error path and about 2.8x and 1.8x from generated fast paths. Those two shapes are a struct with a Json index-signature child and a struct with a Uint8Array field. The synthetic results do not reproduce the larger ratios from the representative set, and nothing in this report depends on that set being available.
The mechanism is consistent across both measurements. Valid documents spend their time in the interpreter and in issue collection, even when no issue is produced. Errors spend time in error-mode handling and in the per-key excess-property check. Thrown SchemaError objects are not the main cost: throwing, returning and bare-issue paths all landed within 13% of each other.
Possible directions
These are candidates I want to discuss, not commitments I am making here:
- An options-aware boolean validation path. Callers that only need accept or reject could enforce a strict contract such as
onExcessProperty: "error"without building issue details on the valid path. - Generated fast paths for common declaration shapes. The Json index signature and Uint8Array shapes currently push a whole struct onto the interpreter; compiling them directly is a contained way to bring more schemas onto the fast path.
- Caching excess-key metadata. Declared property names are fixed per schema, so rebuilding them for every document looks avoidable.
Scope and limits
I do not want to change validation semantics. Any direction has to keep the existing checks and options, including required, enum, pattern, length and onExcessProperty, and generated results need to match the interpreter. The numbers come from one host and are relative signals rather than a service level guarantee.
Activity