Skip to content

Conversation

@zekth
Copy link
Member

@zekth zekth commented Sep 7, 2020

Because calling += operand is cost effective, reducing the number of calls seems like a good move to improve performances.

Reference benchmark

FJS creation x 36,866 ops/sec ±3.36% (74 runs sampled)
JSTR creation x 103,618 ops/sec ±3.28% (78 runs sampled)
CJS creation x 110,871 ops/sec ±2.26% (85 runs sampled)
JSON.stringify array x 3,308 ops/sec ±3.92% (79 runs sampled)
fast-json-stringify array x 5,923 ops/sec ±1.13% (86 runs sampled)
json-strify array x 48,848,583 ops/sec ±0.61% (91 runs sampled)
compile-json-stringify array x 6,132 ops/sec ±1.49% (85 runs sampled)
JSON.stringify long string x 13,234 ops/sec ±0.48% (93 runs sampled)
fast-json-stringify long string x 13,205 ops/sec ±0.44% (92 runs sampled)
json-strify long string x 250,959 ops/sec ±1.04% (91 runs sampled)
compile-json-stringify long string x 12,778 ops/sec ±0.97% (87 runs sampled)
JSON.stringify short string x 4,270,730 ops/sec ±1.23% (86 runs sampled)
fast-json-stringify short string x 24,189,271 ops/sec ±0.92% (93 runs sampled)
json-strify short string x 46,922,094 ops/sec ±0.60% (91 runs sampled)
compile-json-stringify short string x 27,792,567 ops/sec ±0.61% (95 runs sampled)
JSON.stringify obj x 1,998,108 ops/sec ±0.88% (88 runs sampled)
fast-json-stringify obj x 6,616,125 ops/sec ±1.11% (90 runs sampled)
json-strify obj x 50,441,958 ops/sec ±0.94% (93 runs sampled)
compile-json-stringify obj x 6,978,942 ops/sec ±1.06% (93 runs sampled)

Updated code benchmark

FJS creation x 45,313 ops/sec ±1.79% (89 runs sampled)
JSTR creation x 133,403 ops/sec ±0.98% (92 runs sampled)
CJS creation x 133,050 ops/sec ±1.25% (93 runs sampled)
JSON.stringify array x 4,338 ops/sec ±0.49% (93 runs sampled)
fast-json-stringify array x 6,842 ops/sec ±0.13% (98 runs sampled)
json-strify array x 55,356,698 ops/sec ±0.66% (95 runs sampled)
compile-json-stringify array x 6,841 ops/sec ±0.88% (91 runs sampled)
JSON.stringify long string x 14,075 ops/sec ±0.59% (94 runs sampled)
fast-json-stringify long string x 14,324 ops/sec ±0.42% (94 runs sampled)
json-strify long string x 277,193 ops/sec ±0.43% (94 runs sampled)
compile-json-stringify long string x 14,400 ops/sec ±0.36% (97 runs sampled)
JSON.stringify short string x 5,062,643 ops/sec ±0.40% (94 runs sampled)
fast-json-stringify short string x 26,170,935 ops/sec ±0.76% (96 runs sampled)
json-strify short string x 51,178,502 ops/sec ±0.47% (89 runs sampled)
compile-json-stringify short string x 29,463,421 ops/sec ±0.91% (95 runs sampled)
JSON.stringify obj x 2,208,298 ops/sec ±0.53% (96 runs sampled)
fast-json-stringify obj x 6,983,039 ops/sec ±0.41% (96 runs sampled)
json-strify obj x 53,769,162 ops/sec ±0.87% (94 runs sampled)
compile-json-stringify obj x 7,359,243 ops/sec ±0.27% (97 runs sampled)

Checklist

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, good spot!

@mcollina mcollina merged commit a0682b9 into fastify:master Sep 7, 2020
@zekth zekth deleted the improve_perf branch September 7, 2020 12:41
@zekth zekth mentioned this pull request Sep 13, 2020
4 tasks
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.

2 participants