Skip to content

perf: faster object property and date/time serialization#852

Open
mcollina wants to merge 1 commit into
mainfrom
perf-serialization
Open

perf: faster object property and date/time serialization#852
mcollina wants to merge 1 commit into
mainfrom
perf-serialization

Conversation

@mcollina

@mcollina mcollina commented Jul 8, 2026

Copy link
Copy Markdown
Member
  • Fold commas (and the leading { when a required property comes first) into the property key literals, so each property is serialized with a single string append instead of two or three.
  • Format date-time, date and time manually instead of via toISOString and intermediate Date allocations (~4.5x, ~16x and ~17x respectively). Expanded years and invalid dates fall back to the previous path.
  • Replace the bound asInteger with a closure.

Benchmarks (Node 24): formatted time +1605%, formatted date +1493%, date-time +355%, objects +7-15%, arrays of objects +15%. No regressions.

Also fixes invalid JSON output ({,"b":2}) when required lists a key not declared in properties and the first declared property is undefined; regression test added.

@Tony133

Tony133 commented Jul 9, 2026

Copy link
Copy Markdown
Member

there are some conflicts in the index.js

@nigrosimone

Copy link
Copy Markdown
Contributor

Perhaps the readme.md needs to be updated as well https://github.com/fastify/fast-json-stringify#benchmarks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants