Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: cache json strings into const #713

Merged
merged 2 commits into from Apr 23, 2024
Merged

Conversation

nigrosimone
Copy link
Contributor

@nigrosimone nigrosimone commented Apr 22, 2024

npm run bench:cmp

> fast-json-stringify@5.14.1 bench:cmp
> node ./benchmark/bench-cmp-branch.js

Select the branch you want to compare (feature branch):
cache-str
Select the branch you want to compare with (main branch):
master
Checking out "cache-str"
Execute "npm run bench"

> fast-json-stringify@5.14.1 bench
> node ./benchmark/bench.js

short string............................................. x 16,870,462 ops/sec ±2.49% (173 runs sampled)
unsafe short string...................................... x 724,139,578 ops/sec ±0.41% (186 runs sampled)
short string with double quote........................... x 8,446,363 ops/sec ±0.98% (187 runs sampled)
long string without double quotes........................ x 11,556 ops/sec ±0.44% (191 runs sampled)
unsafe long string without double quotes................. x 813,697,981 ops/sec ±1.28% (191 runs sampled)
long string.............................................. x 13,826 ops/sec ±1.17% (186 runs sampled)
unsafe long string....................................... x 886,199,677 ops/sec ±0.45% (190 runs sampled)
number................................................... x 885,289,169 ops/sec ±0.51% (189 runs sampled)
integer.................................................. x 186,926,499 ops/sec ±0.73% (190 runs sampled)
formatted date-time...................................... x 1,180,142 ops/sec ±1.01% (185 runs sampled)
formatted date........................................... x 770,533 ops/sec ±1.26% (184 runs sampled)
formatted time........................................... x 744,215 ops/sec ±1.54% (181 runs sampled)
short array of numbers................................... x 83,572 ops/sec ±2.01% (179 runs sampled)
short array of integers.................................. x 76,748 ops/sec ±1.77% (179 runs sampled)
short array of short strings............................. x 19,934 ops/sec ±0.44% (189 runs sampled)
short array of long strings.............................. x 18,284 ops/sec ±2.77% (177 runs sampled)
short array of objects with properties of different types x 8,478 ops/sec ±1.37% (176 runs sampled)
object with number property.............................. x 742,860,674 ops/sec ±0.44% (189 runs sampled)
object with integer property............................. x 155,007,833 ops/sec ±0.38% (191 runs sampled)
object with short string property........................ x 16,724,070 ops/sec ±1.23% (179 runs sampled)
object with long string property......................... x 11,640 ops/sec ±1.33% (186 runs sampled)
object with properties of different types................ x 1,683,099 ops/sec ±1.09% (188 runs sampled)
simple object............................................ x 8,467,288 ops/sec ±0.88% (189 runs sampled)
simple object with required fields....................... x 9,377,275 ops/sec ±1.91% (182 runs sampled)
object with const string property........................ x 883,884,078 ops/sec ±0.50% (190 runs sampled)
object with const number property........................ x 885,943,123 ops/sec ±0.45% (191 runs sampled)
object with const bool property.......................... x 887,473,685 ops/sec ±0.51% (191 runs sampled)
object with const object property........................ x 892,204,220 ops/sec ±0.45% (190 runs sampled)
object with const null property.......................... x 881,055,068 ops/sec ±0.65% (190 runs sampled)

Checking out "master"
Execute "npm run bench"

> fast-json-stringify@5.14.1 bench
> node ./benchmark/bench.js

short string............................................. x 16,912,799 ops/sec ±2.45% (174 runs sampled)
unsafe short string...................................... x 734,503,764 ops/sec ±1.31% (185 runs sampled)
short string with double quote........................... x 8,400,416 ops/sec ±1.60% (186 runs sampled)
long string without double quotes........................ x 11,088 ops/sec ±1.01% (179 runs sampled)
unsafe long string without double quotes................. x 738,669,891 ops/sec ±0.48% (189 runs sampled)
long string.............................................. x 11,958 ops/sec ±0.53% (190 runs sampled)
unsafe long string....................................... x 756,187,321 ops/sec ±0.37% (189 runs sampled)
number................................................... x 865,206,823 ops/sec ±1.02% (190 runs sampled)
integer.................................................. x 185,672,593 ops/sec ±0.84% (191 runs sampled)
formatted date-time...................................... x 1,123,406 ops/sec ±1.33% (185 runs sampled)
formatted date........................................... x 750,140 ops/sec ±1.30% (185 runs sampled)
formatted time........................................... x 755,195 ops/sec ±1.16% (184 runs sampled)
short array of numbers................................... x 88,025 ops/sec ±1.69% (179 runs sampled)
short array of integers.................................. x 75,908 ops/sec ±1.83% (181 runs sampled)
short array of short strings............................. x 19,657 ops/sec ±1.18% (189 runs sampled)
short array of long strings.............................. x 18,938 ops/sec ±1.49% (185 runs sampled)
short array of objects with properties of different types x 10,090 ops/sec ±1.62% (181 runs sampled)
object with number property.............................. x 887,652,574 ops/sec ±0.43% (191 runs sampled)
object with integer property............................. x 167,257,031 ops/sec ±2.11% (173 runs sampled)
object with short string property........................ x 16,206,991 ops/sec ±2.19% (177 runs sampled)
object with long string property......................... x 11,758 ops/sec ±1.09% (184 runs sampled)
object with properties of different types................ x 1,665,238 ops/sec ±1.71% (178 runs sampled)
simple object............................................ x 8,314,669 ops/sec ±1.03% (188 runs sampled)
simple object with required fields....................... x 7,716,424 ops/sec ±1.60% (176 runs sampled)
object with const string property........................ x 691,814,706 ops/sec ±0.54% (188 runs sampled)
object with const number property........................ x 688,577,394 ops/sec ±0.79% (186 runs sampled)
object with const bool property.......................... x 721,388,123 ops/sec ±2.22% (181 runs sampled)
object with const object property........................ x 839,403,044 ops/sec ±0.92% (187 runs sampled)
object with const null property.......................... x 881,096,651 ops/sec ±0.77% (191 runs sampled)

short string..............................................-0.25%
unsafe short string.......................................-1.41%
short string with double quote............................+0.55%
long string without double quotes.........................+4.22%
unsafe long string without double quotes.................+10.16%
long string..............................................+15.62%
unsafe long string.......................................+17.19%
number....................................................+2.32%
integer...................................................+0.68%
formatted date-time.......................................+5.05%
formatted date............................................+2.72%
formatted time............................................-1.45%
short array of numbers....................................-5.06%
short array of integers...................................+1.11%
short array of short strings..............................+1.41%
short array of long strings...............................-3.45%
short array of objects with properties of different types-15.98%
object with number property..............................-16.31%
object with integer property..............................-7.32%
object with short string property.........................+3.19%
object with long string property.............................-1%
object with properties of different types.................+1.07%
simple object.............................................+1.84%
simple object with required fields.......................+21.52%
object with const string property........................+27.76%
object with const number property........................+28.66%
object with const bool property..........................+23.02%
object with const object property.........................+6.29%
object with const null property...............................0%
Back to cache-str 651d0e0

image

Checklist

Signed-off-by: Nigro Simone <nigro.simone@gmail.com>
@mcollina mcollina merged commit 0fdf19e into fastify:master Apr 23, 2024
19 checks passed
@nigrosimone nigrosimone deleted the cache-str branch May 16, 2024 04:21
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.

None yet

3 participants