Schema validation performance versus Ajv

Abierto
#10,772 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Activo
Stack tecnológico
typescript
Área
performance

Línea de trabajo

Start by locating the Effect Schema interpreter, issue collection and generated fast paths, then compare their behavior with the reproducible benchmarks for structs containing a Json index-signature child or a Uint8Array field. Measure valid and error paths and check the existing required, enum, pattern, length and onExcessProperty options. Done means a measured improvement with generated results matching interpreter behavior and validation semantics preserved.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
16.7k
Forks
808
Merge medio
21 h 22 min
PR fusionados (30 d)
486

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Effect-TS/effect

Todos los issues de Effect-TS/effect

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.