Back to browse
Fastify's slow startup is an AJV problem – here's a drop-in fix

Fastify's slow startup is an AJV problem – here's a drop-in fix

by greatvenerable·Mar 14, 2026·2 points·0 comments

AI Analysis

●●SolidSolve My ProblemDark Horse

JetValidator cuts Fastify startup from 658ms to 122ms with 100 routes and complex schemas.

Strengths
  • 5x faster schema compilation with removeAdditional, useDefaults, coerceTypes enabled
  • Drop-in replacement requires no code changes to existing Fastify applications
Weaknesses
  • Show HN URL links to AJV docs, not the actual @jetio/fastify-validator package
  • Only matters for users with 100+ routes — most apps won't see meaningful gains
Target Audience

Fastify users with many routes or serverless deployments

Similar To

AJV · fast-json-stringify

Post Description

When using schemas, Fastify's startup speed is heavily affected by its schema compiler, AJV. AJV compiles every schema on startup. That's not the problem. The problem is it's quite slow, and they admit this themselves on their docs: https://ajv.js.org/guide/getting-started.html The more routes, the more complex your schemas, the longer you wait. For most people this isn't a bottleneck — schemas are relatively simple and routes are few. But for serverless functions, situations where every ms counts, or where you need to compile schemas on demand, it matters. Swapping the schema compiler fixes it. 100 routes, complex schemas (allOf/oneOf/anyOf/conditionals): JetValidator has removeAdditional, useDefaults and coerceTypes enabled. AJV has none, while fastify's default also has those 3 options enabled internally

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...

Similar Projects

SaaS●●Solid

Idea validation using real problem discussions

Type a problem and the site pulls live discussion snippets (with relevance signals) from places like Reddit so you can see how people actually phrase complaints. The UI makes scanning quick — cards show context, subreddit and comment counts — but it's essentially a focused search + surfacing layer; interesting and immediately useful, but not a deep analytics play yet (no clustering, source transparency, or deduping shown).

Solve My ProblemNiche GemSlick
muriithiKabogo
103mo ago