lucagez / slow-json-stringify

The slowest stringifier in the known universe. Just kidding, it's the fastest (:
https://github.com/lucagez/slow-json-stringify
MIT License
468 stars 17 forks source link

Increase performance slightly #31

Open kurtextrem opened 2 years ago

kurtextrem commented 2 years ago
Benchmark: Before # Benchmarks Benchmarks performed on: - native **JSON.stringify** - **fast-json-stringify** - **slow-json-stringify** ## small-object ```bash native x 4,193,297 ops/sec ±0.73% (93 runs sampled) fast-json-stringify x 60,026,740 ops/sec ±0.48% (91 runs sampled) slow-json-stringify x 61,442,849 ops/sec ±0.50% (94 runs sampled) # slow-json-stringify is +2.36% faster ``` ## small-array ```bash native x 370,801 ops/sec ±0.52% (94 runs sampled) fast-json-stringify x 448,691 ops/sec ±0.43% (96 runs sampled) slow-json-stringify x 1,331,594 ops/sec ±0.51% (96 runs sampled) # slow-json-stringify is +196.77% faster ``` ## nested-props-short-text ```bash native x 922,660 ops/sec ±0.46% (95 runs sampled) fast-json-stringify x 4,190,374 ops/sec ±0.68% (94 runs sampled) slow-json-stringify x 13,525,473 ops/sec ±0.56% (92 runs sampled) # slow-json-stringify is +222.77% faster ``` ## much-props-short-text ```bash native x 800,738 ops/sec ±0.38% (94 runs sampled) fast-json-stringify x 1,047,538 ops/sec ±0.40% (95 runs sampled) slow-json-stringify x 3,026,591 ops/sec ±0.97% (88 runs sampled) # slow-json-stringify is +188.92% faster ``` ## much-props-big-text ```bash native x 22,005 ops/sec ±0.68% (92 runs sampled) fast-json-stringify x 20,376 ops/sec ±0.71% (90 runs sampled) slow-json-stringify x 3,392,929 ops/sec ±0.49% (93 runs sampled) # slow-json-stringify is +15318.90% faster ``` ## big-text ```bash native x 274,816 ops/sec ±0.43% (92 runs sampled) fast-json-stringify x 285,642 ops/sec ±0.51% (91 runs sampled) slow-json-stringify x 62,128,675 ops/sec ±0.69% (91 runs sampled) # slow-json-stringify is +21650.61% faster ``` ## big-array-short-text ```bash native x 4,678 ops/sec ±0.47% (93 runs sampled) slow-json-stringify x 11,670 ops/sec ±0.44% (93 runs sampled) # slow-json-stringify is +149.52% faster ``` ## big-array-long-text ```bash native x 103 ops/sec ±0.59% (76 runs sampled) slow-json-stringify x 11,480 ops/sec ±0.62% (93 runs sampled) # slow-json-stringify is +11044.66% faster ``` ## big-array-long-number ```bash native x 1,301 ops/sec ±0.75% (91 runs sampled) slow-json-stringify x 4,023 ops/sec ±1.07% (91 runs sampled) # slow-json-stringify is +209.46% faster ``` ## undefined properties ```bash native x 2,456,945 ops/sec ±0.60% (95 runs sampled) fast-json-stringify x 8,646,794 ops/sec ±0.49% (93 runs sampled) slow-json-stringify x 23,159,091 ops/sec ±0.57% (89 runs sampled) # slow-json-stringify is +167.83% faster ```
After # Benchmarks Benchmarks performed on: - native **JSON.stringify** - **fast-json-stringify** - **slow-json-stringify** ## small-object ```bash native x 4,418,329 ops/sec ±0.36% (91 runs sampled) fast-json-stringify x 62,240,693 ops/sec ±0.41% (93 runs sampled) slow-json-stringify x 70,296,883 ops/sec ±0.49% (94 runs sampled) # slow-json-stringify is +12.94% faster ``` ## small-array ```bash native x 382,636 ops/sec ±0.39% (91 runs sampled) fast-json-stringify x 355,617 ops/sec ±0.34% (95 runs sampled) slow-json-stringify x 1,504,099 ops/sec ±0.42% (93 runs sampled) # slow-json-stringify is +293.09% faster ``` ## nested-props-short-text ```bash native x 958,195 ops/sec ±0.48% (92 runs sampled) fast-json-stringify x 4,036,352 ops/sec ±0.48% (93 runs sampled) slow-json-stringify x 16,360,174 ops/sec ±0.78% (86 runs sampled) # slow-json-stringify is +305.32% faster ``` ## much-props-short-text ```bash native x 860,514 ops/sec ±0.42% (92 runs sampled) fast-json-stringify x 1,067,713 ops/sec ±0.47% (97 runs sampled) slow-json-stringify x 3,505,841 ops/sec ±0.67% (92 runs sampled) # slow-json-stringify is +228.35% faster ``` ## much-props-big-text ```bash native x 22,928 ops/sec ±0.69% (94 runs sampled) fast-json-stringify x 21,234 ops/sec ±0.81% (92 runs sampled) slow-json-stringify x 3,854,902 ops/sec ±0.38% (93 runs sampled) # slow-json-stringify is +16713.08% faster ``` ## big-text ```bash native x 284,610 ops/sec ±0.41% (92 runs sampled) fast-json-stringify x 299,126 ops/sec ±0.38% (95 runs sampled) slow-json-stringify x 74,967,337 ops/sec ±1.44% (89 runs sampled) # slow-json-stringify is +24962.13% faster ``` ## big-array-short-text ```bash native x 4,885 ops/sec ±0.57% (91 runs sampled) slow-json-stringify x 12,722 ops/sec ±0.63% (91 runs sampled) # slow-json-stringify is +160.46% faster ``` ## big-array-long-text ```bash native x 108 ops/sec ±0.55% (79 runs sampled) slow-json-stringify x 12,935 ops/sec ±0.26% (91 runs sampled) # slow-json-stringify is +11876.85% faster ``` ## big-array-long-number ```bash native x 1,377 ops/sec ±0.35% (94 runs sampled) slow-json-stringify x 4,512 ops/sec ±0.91% (89 runs sampled) # slow-json-stringify is +227.91% faster ``` ## undefined properties ```bash native x 2,656,347 ops/sec ±0.50% (92 runs sampled) fast-json-stringify x 8,344,745 ops/sec ±0.30% (96 runs sampled) slow-json-stringify x 26,317,667 ops/sec ±0.46% (92 runs sampled) # slow-json-stringify is +215.38% faster ```

Run on a 2019 MB Pro i7 2,6 Ghz.

This is achieved by:

(cc https://github.com/developit/microbundle/issues/892 for more mangling 'performance', since the hoisting lead to less byte savings in the bundle)

cjk commented 2 years ago

This looks promising, why is it stalled?

cjk commented 2 years ago

Thank you! :tada:

kurtextrem commented 2 years ago

Thank you! 🎉

There is not much more to optimize on the hot path as far as I can see.

MarcoLeko commented 2 years ago

Is there anything we can do about to make these changes mergeable? Seems like this PR got stale for a few months already