You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
JSON.stringify more than twice as fast in V8 v. 13.8 #782
This is pretty important results. We would need to do a bit more extensive testing and see what is the impact in Fastify itself, but this is great for the ecosystem.
Hey everyone, just curious if this project is still active. I’ve noticed less inclination or interest in merging PRs. Is it becoming more of a chore to review them due to AI, or has interest in the project simply waned?
In the past, there was much more responsiveness regarding PRs; nowadays, I see many sitting there unreviewed, so I assumed there was less interest. But I see you're working on it, so you've already answered my question 😂
Hi guys. I was checking the current state of the library and decided to start by checking whether it still offers a performance advantage over JSON.stringify. Sorry it will be a lot of text here.
My focus was Node.js 26 and typical API responses: objects with dynamic strings, numbers, booleans, nested objects and arrays. I also tried several experimental serializers to see how much performance we could get from knowing the schema, even with fewer requirements than FJS.
Here is what I found:
The benchmark needs to consume the resulting string
One important detail is that returning a string does not necessarily mean all the work of building it has happened.
FJS returns an unflattened string (a tree of references to smaller string pieces, also called a rope). Native JSON.stringify returns a flat string, with its characters already stored contiguously. Concatenation can therefore look very cheap in a serialization-only benchmark because some copying is deferred.
This includes serialization and byte length counting, without route or socket overhead. It does not include actual UTF-8 output encoding or the complete HTTP response path.
Results for realistic response shapes
Response
JSON.stringify, ops/sec
FJS, ops/sec
Native throughput advantage
Profile: eight fields
4,685,946
2,581,759
1.82×
Account with nested address
5,900,040
2,950,067
2.00×
Four nested objects
3,945,905
1,926,453
2.05×
Order with customer and line items
1,954,491
918,206
2.13×
Metrics with numeric samples and labels
1,961,967
910,054
2.16×
Catalog with products and tag arrays
1,083,493
425,680
2.55×
Unicode profile with nested fields
1,999,060
973,356
2.05×
*all the benchmarks I did also included unmerged optimization: #886
Why schema knowledge helps less now, and what I tried
V8 already remembers a lot about the object shape
One of FJS’s important advantages is knowing the property names ahead of time: it can escape them once and embed them in the generated serializer. Modern V8 removes much of that advantage for ordinary objects with repeated shapes. Its JSON “express lane” records when a hidden class has suitable enumerable string keys that do not require escaping. Subsequent objects sharing that hidden class can have their keys copied without repeating those checks.
We can beat native at returning an unflattened string
I built an experimental serializer with a native addon (that was doing the sam SIMD operations as the native serializer) for checking whether strings need escaping. It did beat native in several serialization-only tests.
But the result changed when I included byte-length counting:
Response
Native, serialize only
Prototype, serialize only
Native + byte length
Prototype + byte length
{ id, name, active }
69 ns
56 ns
91 ns
135 ns
Eight-field profile
172 ns
151 ns
197 ns
294 ns
Four nested objects
252 ns
181 ns
278 ns
384 ns
Unicode profile
442 ns
260 ns
509 ns
813 ns
Some optimizations worked, but did not produce a general win
Moving string safety checks into C++ was successful, especially for longer ASCII values. For an object containing a 1,024-character ASCII field, a js took about 1,775 ns; replacing that check with the addon reduced it to 278 ns. So there was a real win over the JS implementation, and even over that native-to-Buffer baseline, but not over raw native serialization.
Delegating nested objects to JSON.stringify also helped. In one test, manually handling the outer structure and delegating a string-containing child reduced serialization from 137 ns to 105 ns, compared with 142 ns for fully native serialization. After byte-length counting, however, the hybrid took 186 ns against native’s 168 ns. Delegating larger arrays was useful too: in the built-in large-array benchmark, FJS’s native-delegation strategy essentially matched native.
Reducing intermediate strings helped as well. Merging quotes into surrounding generated literals reduced the prototype’s serialization-plus-byte-length time by roughly 6–20% across nine response cases. Native still won all of them.
I also ran the same benchmark on Node.js 24. Native still came out ahead of FJS on these response cases, but the gap is much smaller than on Node.js 26.
These numbers include serialization + Buffer.byteLength, as before. I'm +1 for dropping the FJS serialization in the Fastify v6.
Hi all, an update on this, now that v7.3.10 is out.
Since v7.3.5 there is a new option, objectMechanism: 'native'. On Node.js 25+ it copies the input into objects shaped by the schema and passes them to the native JSON.stringify, so the schema is still applied and the V8 fast path is always taken. On Node.js 24 and older the option does nothing for now (#938 is a draft under evaluation).
In short: with the option fast-json-stringify is now very close to the native JSON.stringify on plain data, and faster than it when the data has dates or properties that the schema does not declare.
Numbers on Node v26.13.0, Apple Silicon, in operations per second (higher is better):
Case
JSON.stringify
fast-json-stringify v7.3.10
fast-json-stringify v7.3.10 with objectMechanism: 'native'
list of 50 objects with 8 properties
97.0k
54.2k
89.8k
same list, schema with a $ref to a shared schema
97.7k
55.2k
92.5k
same list, each object has 3 more properties not in the schema
22.9k
54.7k
90.2k
one object with 2 strings and 1 Date
1.25M
3.66M
6.52M
So, to answer the question:
On plain data JSON.stringify is still the fastest. On a list of objects fast-json-stringify with objectMechanism: 'native' is 7% behind it, instead of 44% without the option. Across the 22 plain cases I measured it is 5% to 16% behind.
When the data has Date values, or properties that the schema does not declare (an ORM entity, for example), fast-json-stringify is 4 to 5 times faster than JSON.stringify, because JSON.stringify leaves its fast path.
The schema still does what JSON.stringify cannot do: it removes the properties that are not declared, so nothing is sent by mistake.
The last releases made the option work on the schemas people really write: nullable, enum, format and additionalProperties: false in v7.3.9 (#936), $ref in v7.3.10 (#937).
Activity
mcollina commentedon Aug 29, 2025
Let's see when this reaches Node.js itself! :)
jsumners commentedon Aug 29, 2025
I would pay attention to the "Limitations" section.
nigrosimone commentedon Oct 17, 2025
Node.js 25 is here! https://nodejs.org/en/blog/release/v25.0.0
node v25.0.0
node v24.0.2
mcollina commentedon Oct 17, 2025
This is pretty important results. We would need to do a bit more extensive testing and see what is the impact in Fastify itself, but this is great for the ecosystem.
jsumners commentedon Oct 17, 2025
Do we have any way to feature detect it?
mcollina commentedon Oct 18, 2025
We can just check what version of Node.js we are running.
gurgunday commentedon Oct 22, 2025
This is insane!
cesco69 commentedon Feb 6, 2026
Result on Node.JS v25.2.0 and fast-json-stringify v6.3.0
Same result, but only FJS VS JSON.stringify
cesco69 commentedon Sep 22, 2026
Hey everyone, just curious if this project is still active. I’ve noticed less inclination or interest in merging PRs. Is it becoming more of a chore to review them due to AI, or has interest in the project simply waned?
mcollina commentedon Sep 22, 2026
Given that we landed something 4 days ago, how can you say this is inactive?
cesco69 commentedon Sep 24, 2026
In the past, there was much more responsiveness regarding PRs; nowadays, I see many sitting there unreviewed, so I assumed there was less interest. But I see you're working on it, so you've already answered my question 😂
ivan-tymoshenko commentedon Oct 1, 2026
Hi guys. I was checking the current state of the library and decided to start by checking whether it still offers a performance advantage over
JSON.stringify. Sorry it will be a lot of text here.My focus was Node.js 26 and typical API responses: objects with dynamic strings, numbers, booleans, nested objects and arrays. I also tried several experimental serializers to see how much performance we could get from knowing the schema, even with fewer requirements than FJS.
Here is what I found:
The benchmark needs to consume the resulting string
One important detail is that returning a string does not necessarily mean all the work of building it has happened.
FJS returns an unflattened string (a tree of references to smaller string pieces, also called a rope). Native
JSON.stringifyreturns a flat string, with its characters already stored contiguously. Concatenation can therefore look very cheap in a serialization-only benchmark because some copying is deferred.I updated the benchmark to measure:
This includes serialization and byte length counting, without route or socket overhead. It does not include actual UTF-8 output encoding or the complete HTTP response path.
Results for realistic response shapes
*all the benchmarks I did also included unmerged optimization: #886
ivan-tymoshenko commentedon Oct 1, 2026
Why schema knowledge helps less now, and what I tried
V8 already remembers a lot about the object shape
One of FJS’s important advantages is knowing the property names ahead of time: it can escape them once and embed them in the generated serializer. Modern V8 removes much of that advantage for ordinary objects with repeated shapes. Its JSON “express lane” records when a hidden class has suitable enumerable string keys that do not require escaping. Subsequent objects sharing that hidden class can have their keys copied without repeating those checks.
We can beat native at returning an unflattened string
I built an experimental serializer with a native addon (that was doing the sam SIMD operations as the native serializer) for checking whether strings need escaping. It did beat native in several serialization-only tests.
But the result changed when I included byte-length counting:
{ id, name, active }Some optimizations worked, but did not produce a general win
Moving string safety checks into C++ was successful, especially for longer ASCII values. For an object containing a 1,024-character ASCII field, a js took about 1,775 ns; replacing that check with the addon reduced it to 278 ns. So there was a real win over the JS implementation, and even over that native-to-Buffer baseline, but not over raw native serialization.
Delegating nested objects to
JSON.stringifyalso helped. In one test, manually handling the outer structure and delegating a string-containing child reduced serialization from 137 ns to 105 ns, compared with 142 ns for fully native serialization. After byte-length counting, however, the hybrid took 186 ns against native’s 168 ns. Delegating larger arrays was useful too: in the built-in large-array benchmark, FJS’s native-delegation strategy essentially matched native.Reducing intermediate strings helped as well. Merging quotes into surrounding generated literals reduced the prototype’s serialization-plus-byte-length time by roughly 6–20% across nine response cases. Native still won all of them.
ivan-tymoshenko commentedon Oct 1, 2026
I also ran the same benchmark on Node.js 24. Native still came out ahead of FJS on these response cases, but the gap is much smaller than on Node.js 26.
These numbers include serialization +
Buffer.byteLength, as before. I'm +1 for dropping the FJS serialization in the Fastify v6.Tony133 commentedon Nov 22, 2026
Hi all, an update on this, now that v7.3.10 is out.
Since v7.3.5 there is a new option,
objectMechanism: 'native'. On Node.js 25+ it copies the input into objects shaped by the schema and passes them to the nativeJSON.stringify, so the schema is still applied and the V8 fast path is always taken. On Node.js 24 and older the option does nothing for now (#938 is a draft under evaluation).In short: with the option fast-json-stringify is now very close to the native
JSON.stringifyon plain data, and faster than it when the data has dates or properties that the schema does not declare.Numbers on Node v26.13.0, Apple Silicon, in operations per second (higher is better):
objectMechanism: 'native'$refto a shared schemaDateSo, to answer the question:
JSON.stringifyis still the fastest. On a list of objects fast-json-stringify withobjectMechanism: 'native'is 7% behind it, instead of 44% without the option. Across the 22 plain cases I measured it is 5% to 16% behind.Datevalues, or properties that the schema does not declare (an ORM entity, for example), fast-json-stringify is 4 to 5 times faster thanJSON.stringify, becauseJSON.stringifyleaves its fast path.JSON.stringifycannot do: it removes the properties that are not declared, so nothing is sent by mistake.The last releases made the option work on the schemas people really write:
nullable,enum,formatandadditionalProperties: falsein v7.3.9 (#936),$refin v7.3.10 (#937).To try it:
or in Fastify: