← Back to Node.js performance map
Node.js Performance

Fast JSON Serialization

Use schemas to serialize hot JSON responses faster.

json

Detailed Description

JSON serialization can become expensive on hot endpoints. Schema-based serializers precompile the response shape and can reduce CPU time.

This works best when response objects have stable shapes. If the schema changes frequently or data is highly dynamic, the complexity may not be worth it.

Mental Model

schema
-> compiled serializer
-> res.end(serialized)

When To Use

  • ->Hot endpoints return many JSON objects
  • ->JSON.stringify shows up in CPU profiles
  • ->Response shape is predictable
Tools: fast-json-stringify, Fastify schemas
fast-json.js

Live Editor

Loading...

Output

Run code to see output...

Comments

Sign in to leave a comment. Your name and photo come from Google; nothing else is shared.

Loading comments...