-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
console,internal/errors: improve error perf #13743
Conversation
lib/console.js
Outdated
err.message = util.format.apply(null, args); | ||
Error.captureStackTrace(err, trace); | ||
this.error(err.stack); | ||
const o = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can keep the more descriptive variable name here (err
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's not really a typical error anymore but I do not have any strong feelings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code changes LGTM. Commit message-wise, I'd prefer if it addresses what is changed rather than what are the results of the changes.
Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance.
Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided.
932788a
to
e16faad
Compare
I changed the commit messages. |
@@ -28,7 +28,6 @@ function makeNodeError(Base) { | |||
constructor(key, ...args) { | |||
super(message(key, args)); | |||
this[kCode] = key; | |||
Error.captureStackTrace(this, NodeError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm -1 on removing this line. The fact that NodeError
is being used in here should not be visible to the end user. This intentionally removes that frame from the stack trace to provide that transparency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The frame is not visible because newer v8 versions remove the constructor frame by default.
That's the reason why I removed the Error.captureStackTrace
call. Do you maybe know a better description for the commit message to make it clearer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked all other occurrences as well and they are always needed besides here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh nice... I knew that change was coming but I wasn't expecting it until 6.x for some reason. :-) ... that's a happy surprise. I withdraw the objection then!
Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Quick sanity of |
Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Using a object instead of an Error is sufficient as the Error itself won't be used but only the stack trace that would otherwise be created twice. This improves the overall .trace() performance. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
Newer v8 versions exclude the constructor from the stack trace so the recalculation of the trace can be avoided. PR-URL: #13743 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
This increases the performance for
console.trace
and creating a new NodeError by factor 2-3.Newer v8 versions exclude the constructor from the stack trace
so the recalculation of the trace can be avoided.
Using a object instead of an Error is sufficient for console.trace as the Error
itself won't be used but only the stack trace that would
otherwise be created twice.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
console, internal/errors