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

util: fix inspect performance bug #20007

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,11 @@ function formatValue(ctx, value, recurseTimes, ln) {
}
}

// 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

.includes() unless it has a performance penalty?

Copy link
Member Author

Choose a reason for hiding this comment

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

It had a performance penalty the last time I checked.

Copy link
Member

Choose a reason for hiding this comment

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

indexOf should be much faster than anything else.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it is a case for @nodejs/v8 performance group to look into then.

return ctx.stylize('[Circular]', 'special');

let keys;
let symbols = Object.getOwnPropertySymbols(value);

Expand Down Expand Up @@ -625,11 +630,6 @@ function formatValue(ctx, value, recurseTimes, ln) {
}
}

// 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)
return ctx.stylize('[Circular]', 'special');

if (recurseTimes != null) {
if (recurseTimes < 0)
return ctx.stylize(`[${constructor || tag || 'Object'}]`, 'special');
Expand Down