Fastify default AJV: 658ms AJV no options: 425ms @jetio/fastify-validator: 122ms
100 routes, 500 properties per schema: Same options setup.
Fastify default AJV: 69s AJV no options: 47s @jetio/fastify-validator: 2.6s
JetValidator with full options enabled. AJV with none. Still 18x faster. Benchmarks are reproducible, Run them yourself: https://github.com/official-jetio/fastify-validator
It's a custom schemaController or buildValidator for Fastify that lets you swap the compiler it uses. Two functions to drop it in: npm i @jetio/fastify-validator
const fastify = Fastify({ schemaController: createJetValidatorController({ removeAdditional: true, useDefaults: true, coerceTypes: true, }), });
Or using buildValidator directly if you need more control:
const fastify = Fastify({ schemaController: { compilersFactory: { buildValidator: createJetValidatorCompiler({ removeAdditional: true, useDefaults: true, coerceTypes: true, }), }, }, });
This was built specifically for developers who have issues with Fastify startup time or want faster startups. If you don't then you don't need this.
The package is powered by @jetio/validator, a full AJV replacement built from scratch. 19x faster compilation on average across 62 schemas. 72% overall win rate in validation. 99.5% JSON Schema compliant across drafts 06 through 2020-12. Zero dependencies. 26KB gzipped. Everything AJV does is built in, formats, custom keywords, $data, $ref, async validation and custom elseIf keyword no extra packages needed.
Fastify validator: https://github.com/official-jetio/fastify-validator Schema Builder with json schema compliant type inference: https://github.com/official-jetio/schema-builder Validator: https://github.com/official-jetio/validator Benchmarks: https://github.com/official-jetio/validator#benchmarks Docs: https://github.com/official-jetio/validator/blob/main/DOCUME...