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: optimize required props serialization #675

Merged
merged 1 commit into from Jan 27, 2024

Conversation

ivan-tymoshenko
Copy link
Member

@ivan-tymoshenko ivan-tymoshenko commented Jan 27, 2024

It removes a check before adding a comma if there are required props. Which gives you around 8-10% perf boost if object has at least one required property.

Before:
image

After:
image

@Uzlopak Uzlopak added the benchmark Label to run benchmark against PR and main branch label Jan 27, 2024
@Uzlopak
Copy link
Contributor

Uzlopak commented Jan 27, 2024

awesome

Copy link

PR:

short string............................................. x 22,336,523 ops/sec ±0.99% (194 runs sampled)
short string with double quote........................... x 13,144,259 ops/sec ±0.48% (193 runs sampled)
long string without double quotes........................ x 27,196 ops/sec ±0.71% (194 runs sampled)
long string.............................................. x 10,479 ops/sec ±0.21% (193 runs sampled)
number................................................... x 816,841,358 ops/sec ±0.26% (195 runs sampled)
integer.................................................. x 173,853,531 ops/sec ±0.27% (195 runs sampled)
formatted date-time...................................... x 3,570,795 ops/sec ±0.19% (193 runs sampled)
formatted date........................................... x 2,292,872 ops/sec ±2.20% (189 runs sampled)
formatted time........................................... x 2,339,269 ops/sec ±0.25% (193 runs sampled)
short array of numbers................................... x 84,088 ops/sec ±0.30% (194 runs sampled)
short array of integers.................................. x 67,049 ops/sec ±0.70% (193 runs sampled)
short array of short strings............................. x 20,036 ops/sec ±0.17% (193 runs sampled)
short array of long strings.............................. x 19,947 ops/sec ±0.19% (192 runs sampled)
short array of objects with properties of different types x 10,740 ops/sec ±0.28% (194 runs sampled)
object with number property.............................. x 815,435,190 ops/sec ±0.06% (195 runs sampled)
object with integer property............................. x 173,592,621 ops/sec ±0.36% (195 runs sampled)
object with short string property........................ x 22,167,373 ops/sec ±0.31% (194 runs sampled)
object with long string property......................... x 10,495 ops/sec ±0.21% (192 runs sampled)
object with properties of different types................ x 2,224,259 ops/sec ±0.25% (193 runs sampled)
simple object............................................ x 9,741,886 ops/sec ±0.23% (194 runs sampled)
simple object with required fields....................... x 10,222,838 ops/sec ±0.33% (194 runs sampled)
object with const string property........................ x 820,288,245 ops/sec ±0.08% (195 runs sampled)
object with const number property........................ x 820,601,143 ops/sec ±0.06% (195 runs sampled)
object with const bool property.......................... x 820,305,129 ops/sec ±0.06% (195 runs sampled)
object with const object property........................ x 820,228,324 ops/sec ±0.07% (195 runs sampled)
object with const null property.......................... x 820,268,107 ops/sec ±0.06% (195 runs sampled)

MASTER:

short string............................................. x 22,565,383 ops/sec ±0.25% (194 runs sampled)
short string with double quote........................... x 13,174,737 ops/sec ±0.39% (193 runs sampled)
long string without double quotes........................ x 26,994 ops/sec ±1.64% (191 runs sampled)
long string.............................................. x 10,385 ops/sec ±0.22% (193 runs sampled)
number................................................... x 818,416,765 ops/sec ±0.08% (195 runs sampled)
integer.................................................. x 174,373,202 ops/sec ±0.08% (195 runs sampled)
formatted date-time...................................... x 3,571,921 ops/sec ±0.18% (194 runs sampled)
formatted date........................................... x 2,332,611 ops/sec ±0.22% (193 runs sampled)
formatted time........................................... x 2,338,759 ops/sec ±0.24% (193 runs sampled)
short array of numbers................................... x 84,737 ops/sec ±0.26% (194 runs sampled)
short array of integers.................................. x 67,045 ops/sec ±0.72% (193 runs sampled)
short array of short strings............................. x 19,884 ops/sec ±0.18% (192 runs sampled)
short array of long strings.............................. x 20,008 ops/sec ±0.19% (193 runs sampled)
short array of objects with properties of different types x 10,666 ops/sec ±0.19% (194 runs sampled)
object with number property.............................. x 815,784,252 ops/sec ±0.06% (195 runs sampled)
object with integer property............................. x 173,982,392 ops/sec ±0.07% (195 runs sampled)
object with short string property........................ x 22,101,686 ops/sec ±0.22% (194 runs sampled)
object with long string property......................... x 10,604 ops/sec ±0.17% (195 runs sampled)
object with properties of different types................ x 2,201,328 ops/sec ±0.41% (192 runs sampled)
simple object............................................ x 10,136,445 ops/sec ±0.27% (194 runs sampled)
simple object with required fields....................... x 10,419,121 ops/sec ±0.28% (194 runs sampled)
object with const string property........................ x 819,990,450 ops/sec ±0.08% (195 runs sampled)
object with const number property........................ x 820,399,936 ops/sec ±0.06% (194 runs sampled)
object with const bool property.......................... x 820,410,316 ops/sec ±0.07% (194 runs sampled)
object with const object property........................ x 820,564,928 ops/sec ±0.06% (194 runs sampled)
object with const null property.......................... x 820,188,094 ops/sec ±0.08% (195 runs sampled)

@github-actions github-actions bot removed the benchmark Label to run benchmark against PR and main branch label Jan 27, 2024
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.

love it

@mcollina mcollina merged commit 15a2386 into master Jan 27, 2024
23 checks passed
@Uzlopak Uzlopak deleted the optimized-required-props-serialization branch January 28, 2024 04:14
mcollina added a commit that referenced this pull request Feb 1, 2024
ivan-tymoshenko added a commit that referenced this pull request Feb 4, 2024
mcollina pushed a commit that referenced this pull request Feb 5, 2024
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