Skip to content

JSON.stringify more than twice as fast in V8 v. 13.8 #782

Open

Description

@cesco69

https://v8.dev/blog/json-stringify

Does it still make sense to use fast-json-stringify?

Activity

  1. mcollina commented on Aug 29, 2025

    @mcollina
    Member

    Let's see when this reaches Node.js itself! :)

  2. jsumners commented on Aug 29, 2025

    @jsumners
    Member

    I would pay attention to the "Limitations" section.

  3. nigrosimone commented on Oct 17, 2025

    @nigrosimone
    Contributor

    Node.js 25 is here! https://nodejs.org/en/blog/release/v25.0.0

    We have upgraded V8 to 14.1, bringing major JSON.stringify performance improvements

    node v25.0.0

    nvm use 25
    Now using node v25.0.0 (64-bit)
    
    node ./benchmark/bench-cmp-lib.js
    
    FJS creation x 12,168 ops/sec ±0.99% (89 runs sampled)
    CJS creation x 337,182 ops/sec ±0.88% (94 runs sampled)
    AJV Serialize creation x 65,052,643 ops/sec ±2.74% (85 runs sampled)
    json-accelerator creation x 753,516 ops/sec ±3.13% (83 runs sampled)
    JSON.stringify array x 16,703 ops/sec ±1.11% (97 runs sampled)
    fast-json-stringify array default x 9,602 ops/sec ±3.06% (85 runs sampled)
    json-accelerator array x 8,730 ops/sec ±2.14% (86 runs sampled)
    fast-json-stringify array json-stringify x 9,834 ops/sec ±3.82% (93 runs sampled)
    compile-json-stringify array x 8,767 ops/sec ±3.36% (84 runs sampled)
    AJV Serialize array x 9,148 ops/sec ±2.07% (85 runs sampled)
    JSON.stringify large array x 643 ops/sec ±1.86% (83 runs sampled)
    fast-json-stringify large array default x 380 ops/sec ±1.60% (78 runs sampled)
    fast-json-stringify large array json-stringify x 639 ops/sec ±1.72% (86 runs sampled)
    compile-json-stringify large array x 391 ops/sec ±1.51% (87 runs sampled)
    AJV Serialize large array x 425 ops/sec ±1.38% (84 runs sampled)
    JSON.stringify long string x 41,023 ops/sec ±1.42% (93 runs sampled)
    fast-json-stringify long string x 41,082 ops/sec ±2.10% (92 runs sampled)
    json-accelerator long string x 40,047 ops/sec ±2.64% (89 runs sampled)
    compile-json-stringify long string x 39,137 ops/sec ±3.33% (88 runs sampled)
    AJV Serialize long string x 20,818 ops/sec ±1.60% (91 runs sampled)
    JSON.stringify short string x 20,847,735 ops/sec ±1.65% (88 runs sampled)
    fast-json-stringify short string x 54,187,410 ops/sec ±3.56% (81 runs sampled)
    json-accelerator short string x 55,769,691 ops/sec ±2.96% (82 runs sampled)
    compile-json-stringify short string x 29,386,773 ops/sec ±3.03% (87 runs sampled)
    AJV Serialize short string x 27,292,367 ops/sec ±4.29% (82 runs sampled)
    JSON.stringify obj x 10,719,926 ops/sec ±2.35% (89 runs sampled)
    fast-json-stringify obj x 9,465,755 ops/sec ±2.96% (84 runs sampled)
    json-accelerator obj x 10,408,435 ops/sec ±2.48% (85 runs sampled)
    compile-json-stringify obj x 18,702,800 ops/sec ±1.61% (91 runs sampled)
    AJV Serialize obj x 14,826,274 ops/sec ±1.28% (92 runs sampled)
    JSON stringify date x 541,364 ops/sec ±2.38% (89 runs sampled)
    fast-json-stringify date format x 977,731 ops/sec ±2.92% (87 runs sampled)
    json-accelerate date format x 1,033,027 ops/sec ±1.54% (93 runs sampled)
    compile-json-stringify date format x 535,329 ops/sec ±6.02% (89 runs sampled)
    

    node v24.0.2

    nvm use 24
    Now using node v24.0.2 (64-bit)
    
    node ./benchmark/bench-cmp-lib.js
    
    FJS creation x 11,367 ops/sec ±1.18% (87 runs sampled)
    CJS creation x 292,899 ops/sec ±5.53% (85 runs sampled)
    AJV Serialize creation x 44,973,297 ops/sec ±7.08% (66 runs sampled)
    json-accelerator creation x 519,916 ops/sec ±6.09% (74 runs sampled)
    JSON.stringify array x 6,664 ops/sec ±6.51% (74 runs sampled)
    fast-json-stringify array default x 6,114 ops/sec ±6.85% (70 runs sampled)
    json-accelerator array x 4,174 ops/sec ±8.32% (69 runs sampled)
    fast-json-stringify array json-stringify x 7,428 ops/sec ±6.18% (79 runs sampled)
    compile-json-stringify array x 6,411 ops/sec ±6.82% (76 runs sampled)
    AJV Serialize array x 6,803 ops/sec ±5.83% (81 runs sampled)
    JSON.stringify large array x 245 ops/sec ±7.76% (72 runs sampled)
    fast-json-stringify large array default x 260 ops/sec ±6.72% (72 runs sampled)
    fast-json-stringify large array json-stringify x 249 ops/sec ±6.11% (72 runs sampled)
    compile-json-stringify large array x 254 ops/sec ±7.36% (70 runs sampled)
    AJV Serialize large array x 296 ops/sec ±5.66% (73 runs sampled)
    JSON.stringify long string x 31,841 ops/sec ±5.90% (80 runs sampled)
    fast-json-stringify long string x 30,759 ops/sec ±6.23% (77 runs sampled)
    json-accelerator long string x 30,178 ops/sec ±5.85% (78 runs sampled)
    compile-json-stringify long string x 31,749 ops/sec ±4.51% (80 runs sampled)
    AJV Serialize long string x 16,375 ops/sec ±5.91% (83 runs sampled)
    JSON.stringify short string x 10,009,356 ops/sec ±6.96% (76 runs sampled)
    fast-json-stringify short string x 39,025,110 ops/sec ±5.69% (72 runs sampled)
    json-accelerator short string x 35,046,520 ops/sec ±6.82% (68 runs sampled)
    compile-json-stringify short string x 22,457,409 ops/sec ±6.31% (73 runs sampled)
    AJV Serialize short string x 22,456,193 ops/sec ±5.27% (75 runs sampled)
    JSON.stringify obj x 3,974,667 ops/sec ±5.40% (78 runs sampled)
    fast-json-stringify obj x 7,713,986 ops/sec ±5.73% (80 runs sampled)
    json-accelerator obj x 5,612,044 ops/sec ±5.00% (78 runs sampled)
    compile-json-stringify obj x 14,201,171 ops/sec ±7.41% (75 runs sampled)
    AJV Serialize obj x 10,346,233 ops/sec ±6.73% (73 runs sampled)
    JSON stringify date x 443,078 ops/sec ±5.86% (77 runs sampled)
    fast-json-stringify date format x 788,087 ops/sec ±6.10% (76 runs sampled)
    json-accelerate date format x 994,397 ops/sec ±3.65% (88 runs sampled)
    compile-json-stringify date format x 572,760 ops/sec ±2.37% (87 runs sampled)
    
  4. mcollina commented on Oct 17, 2025

    @mcollina
    Member

    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.

  5. jsumners commented on Oct 17, 2025

    @jsumners
    Member

    Do we have any way to feature detect it?

  6. mcollina commented on Oct 18, 2025

    @mcollina
    Member

    We can just check what version of Node.js we are running.

  7. gurgunday commented on Oct 22, 2025

    @gurgunday
    Member

    This is insane!

  8. cesco69 commented on Feb 6, 2026

    @cesco69
    ContributorAuthor

    Result on Node.JS v25.2.0 and fast-json-stringify v6.3.0

    npm run benchmark
    
    > fast-json-stringify@6.3.0 benchmark
    > node --expose-gc ./benchmark/bench-cmp-lib.js
    
    
    --- creation ---
    🏆 AJV                                      x      14,201,901 ops/sec ±0.13% (18747414 runs sampled)
       json-accelerator                         x         874,175 ops/sec ±11.81% (753985 runs sampled)
       compile-json-stringify                   x         340,772 ops/sec ±0.39% (321509 runs sampled)
       fast-json-stringify                      x           7,911 ops/sec ±0.77% (7468 runs sampled)
    
    --- array ---
    🏆 JSON.stringify                           x          15,839 ops/sec ±0.62% (15438 runs sampled)
       fast-json-stringify [default]            x           8,637 ops/sec ±0.77% (8290 runs sampled)
       json-accelerator                         x           8,335 ops/sec ±0.82% (8021 runs sampled)
       fast-json-stringify [json-stringify]     x           7,594 ops/sec ±1.40% (6920 runs sampled)
       AJV                                      x           7,370 ops/sec ±0.80% (7089 runs sampled)
       compile-json-stringify                   x           6,232 ops/sec ±0.98% (5735 runs sampled)
    
    --- large array ---
    🏆 fast-json-stringify [json-stringify]     x             626 ops/sec ±3.15% (604 runs sampled)
       JSON.stringify                           x             585 ops/sec ±3.75% (554 runs sampled)
       fast-json-stringify [default]            x             354 ops/sec ±3.69% (327 runs sampled)
       compile-json-stringify                   x             329 ops/sec ±4.11% (305 runs sampled)
       AJV                                      x             329 ops/sec ±2.88% (314 runs sampled)
    
    --- long string ---
    🏆 JSON.stringify                           x          23,291 ops/sec ±0.42% (22879 runs sampled)
       compile-json-stringify                   x          22,913 ops/sec ±0.58% (22386 runs sampled)
       json-accelerator                         x          22,564 ops/sec ±0.48% (22097 runs sampled)
       fast-json-stringify                      x          22,348 ops/sec ±0.48% (21762 runs sampled)
       AJV                                      x          17,856 ops/sec ±0.52% (17209 runs sampled)
    
    --- short string ---
    🏆 fast-json-stringify                      x      13,496,065 ops/sec ±0.40% (17727189 runs sampled)
       json-accelerator                         x      12,903,300 ops/sec ±0.16% (16851339 runs sampled)
       compile-json-stringify                   x      11,539,641 ops/sec ±0.11% (14654927 runs sampled)
       AJV                                      x      11,150,869 ops/sec ±0.11% (13944007 runs sampled)
       JSON.stringify                           x       9,823,447 ops/sec ±0.10% (10422896 runs sampled)
    
    --- obj ---
    🏆 AJV                                      x       9,734,818 ops/sec ±0.13% (9653813 runs sampled)
       compile-json-stringify                   x       9,487,641 ops/sec ±0.21% (9778861 runs sampled)
       JSON.stringify                           x       7,930,640 ops/sec ±0.40% (6806905 runs sampled)
       json-accelerator                         x       7,863,358 ops/sec ±0.10% (6806553 runs sampled)
       fast-json-stringify                      x       7,585,403 ops/sec ±0.67% (6181872 runs sampled)
    
    --- date ---
    🏆 json-accelerate                          x       1,252,657 ops/sec ±0.10% (1227925 runs sampled)
       fast-json-stringify                      x       1,244,898 ops/sec ±0.10% (1219516 runs sampled)
       compile-json-stringify                   x         670,475 ops/sec ±0.09% (659750 runs sampled)
       JSON.stringify                           x         661,003 ops/sec ±5.16% (629628 runs sampled)
    

    Same result, but only FJS VS JSON.stringify

    --- array ---
    🏆 JSON.stringify                           x          15,839 ops/sec ±0.62% (15438 runs sampled)
       fast-json-stringify [default]            x           8,637 ops/sec ±0.77% (8290 runs sampled)
       fast-json-stringify [json-stringify]     x           7,594 ops/sec ±1.40% (6920 runs sampled)
    
    --- large array ---
    🏆 fast-json-stringify [json-stringify]     x             626 ops/sec ±3.15% (604 runs sampled)
       JSON.stringify                           x             585 ops/sec ±3.75% (554 runs sampled)
       fast-json-stringify [default]            x             354 ops/sec ±3.69% (327 runs sampled)
    
    --- long string ---
    🏆 JSON.stringify                           x          23,291 ops/sec ±0.42% (22879 runs sampled)
       fast-json-stringify                      x          22,348 ops/sec ±0.48% (21762 runs sampled)
    
    --- short string ---
    🏆 fast-json-stringify                      x      13,496,065 ops/sec ±0.40% (17727189 runs sampled)
       JSON.stringify                           x       9,823,447 ops/sec ±0.10% (10422896 runs sampled)
    
    --- obj ---
       JSON.stringify                           x       7,930,640 ops/sec ±0.40% (6806905 runs sampled)
       fast-json-stringify                      x       7,585,403 ops/sec ±0.67% (6181872 runs sampled)
    
    --- date ---
       fast-json-stringify                      x       1,244,898 ops/sec ±0.10% (1219516 runs sampled)
       JSON.stringify                           x         661,003 ops/sec ±5.16% (629628 runs sampled)
    
  9. added
    question
    benchmark
    on Sep 15, 2026
  10. cesco69 commented on Sep 22, 2026

    @cesco69
    ContributorAuthor

    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?

  11. mcollina commented on Sep 22, 2026

    @mcollina
    Member

    Given that we landed something 4 days ago, how can you say this is inactive?

  12. cesco69 commented on Sep 24, 2026

    @cesco69
    ContributorAuthor

    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 😂

  13. ivan-tymoshenko commented on Oct 1, 2026

    @ivan-tymoshenko
    Member

    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.

    I updated the benchmark to measure:

    const json = serialize(object)
    return Buffer.byteLength(json, 'utf8')

    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

  14. ivan-tymoshenko commented on Oct 1, 2026

    @ivan-tymoshenko
    Member

    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.

  15. ivan-tymoshenko commented on Oct 1, 2026

    @ivan-tymoshenko
    Member

    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.

    Response JSON.stringify FJS Native/FJS
    Profile 2,480,643 2,191,799 1.13×
    Account 2,634,209 2,507,555 1.05×
    Nested objects 2,213,044 1,846,333 1.20×
    Order 977,363 785,791 1.24×
    Metrics 941,291 583,126 1.61×
    Catalog 548,910 368,627 1.49×
    Unicode profile 1,119,782 705,028 1.59×
  16. Tony133 commented on Nov 22, 2026

    @Tony133
    Member

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

    To try it:

    const fastJson = require('fast-json-stringify')
    const stringify = fastJson(schema, { objectMechanism: 'native' })

    or in Fastify:

    const fastify = require('fastify')({
      serializerOpts: { objectMechanism: 'native' }
    })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    benchmarkquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions