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

fix(serializers): properly transfer Symbol based serializers #707

Merged
merged 4 commits into from Sep 13, 2019

Conversation

MickVanDuijn
Copy link
Contributor

When adding serializers through .child, the Symbol based serializers were not transferred. For example: https://github.com/pinojs/pino/blob/master/docs/api.md#serializerssymbolforpino-function

Thanks to @ZwaarContrast for helping with debugging!

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.

Would you mind running https://github.com/pinojs/pino/blob/master/benchmarks/child-creation.bench.js before/after? I would just like to make sure that we are not losing performance on child creation.

lib/proto.js Outdated
instance[serializersSym][k] = serializers[k]
}
for (var bk in bindings.serializers) {
for (var bk of [...Object.getOwnPropertySymbols(bindings.serializers), ...Object.keys(bindings.serializers)]) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you create only 1 instance of these arrays? Given that we will be iterating an array now, I prefer we use a standard for (;;) loop instead, as it's faster than for-of.

Copy link
Member

Choose a reason for hiding this comment

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

this will definitely be slower, even with a for loop. for in is still the fastest way to loop through key names

Copy link
Contributor Author

Choose a reason for hiding this comment

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

split the loops into two parts: a for-in on the keys, plus a for(;;) on the symbols

Copy link
Contributor Author

Choose a reason for hiding this comment

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

timings before this PR:

benchBunyanCreation*10000: 574.174ms
benchBoleCreation*10000: 233.600ms
benchPinoCreation*10000: 241.948ms
benchPinoExtremeCreation*10000: 131.857ms
benchPinoNodeStreamCreation*10000: 250.361ms
benchBunyanCreation*10000: 544.266ms
benchBoleCreation*10000: 225.199ms
benchPinoCreation*10000: 244.614ms
benchPinoExtremeCreation*10000: 127.672ms
benchPinoNodeStreamCreation*10000: 228.082ms

timings after this PR:

benchBunyanCreation*10000: 597.158ms
benchBoleCreation*10000: 241.598ms
benchPinoCreation*10000: 239.223ms
benchPinoExtremeCreation*10000: 134.678ms
benchPinoNodeStreamCreation*10000: 237.142ms
benchBunyanCreation*10000: 510.368ms
benchBoleCreation*10000: 200.756ms
benchPinoCreation*10000: 216.045ms
benchPinoExtremeCreation*10000: 119.050ms
benchPinoNodeStreamCreation*10000: 209.216ms

they seem to heavily fluctuate between runs, but there is no major difference.
Note: the child benchmarks don't include serializers, so this loop is never hit in those benchmarks

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

@jsumners jsumners 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

@github-actions
Copy link

github-actions bot commented Feb 4, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants