Closed
Conversation
In case an object contained a circular reference `Object.keys` was called even though it was not necessary at all. This caused a significant overhead for objects that contained a lot of such entries.
Member
Author
4 tasks
|
|
||
| // Using an array here is actually better for the average case than using | ||
| // a Set. `seen` will only check for the depth and will never grow too large. | ||
| if (ctx.seen.indexOf(value) !== -1) |
Contributor
There was a problem hiding this comment.
.includes() unless it has a performance penalty?
Member
Author
There was a problem hiding this comment.
It had a performance penalty the last time I checked.
Contributor
There was a problem hiding this comment.
indexOf should be much faster than anything else.
Contributor
There was a problem hiding this comment.
Maybe it is a case for @nodejs/v8 performance group to look into then.
mcollina
approved these changes
Apr 13, 2018
Member
mcollina
left a comment
There was a problem hiding this comment.
LGTM
I would love to have/see a benchmark for this.
cjihrig
approved these changes
Apr 13, 2018
Member
Author
|
@mcollina I tested a extreme case: 'use strict';
const util = require('util');
let i = 0;
const obj = {};
while (i++ < 1500) {
obj[i] = {};
}
const circular = {};
for (const k of Object.keys(obj)) {
circular[k] = obj[k];
obj[k].circular = circular;
obj[k].obj = obj;
}
console.time('run');
util.inspect(obj);
console.timeEnd('run');
// Before the patch:
// run: 165971.450ms
// After the patch:
// run: 7377.811ms |
Member
|
I don't believe this qualifies for fast tracking based on the guidance given in https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md#waiting-for-approvals. |
4 tasks
jasnell
approved these changes
Apr 13, 2018
lpinca
approved these changes
Apr 13, 2018
addaleax
approved these changes
Apr 13, 2018
trivikr
approved these changes
Apr 14, 2018
Member
Author
|
Landed in f413f56 |
BridgeAR
added a commit
to BridgeAR/node
that referenced
this pull request
Apr 16, 2018
In case an object contained a circular reference `Object.keys` was called even though it was not necessary at all. This caused a significant overhead for objects that contained a lot of such entries. PR-URL: nodejs#20007 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
jasnell
pushed a commit
that referenced
this pull request
Apr 16, 2018
In case an object contained a circular reference `Object.keys` was called even though it was not necessary at all. This caused a significant overhead for objects that contained a lot of such entries. PR-URL: #20007 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In case an object contained a circular reference
Object.keyswascalled even though it was not necessary at all. This caused a
significant overhead for objects that contained a lot of such entries.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes