-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
assert: improve error check #17574
assert: improve error check #17574
Conversation
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.
Maybe add labels re: not landing on v6.x/v8.x as appropriate. Maybe even v9.x depending on when the optimizations in V8 occurred.
lib/internal/errors.js
Outdated
@@ -140,9 +140,9 @@ class AssertionError extends Error { | |||
if (message) { | |||
super(message); | |||
} else { | |||
if (actual && actual.stack && actual instanceof Error) |
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.
This wasn't a performance microoptimization, but rather an integrity check to avoid Object.create(Error.prototype)
from being recognized as an Error.
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.
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 indeed did not think about this case. I also do not mind if it stays as it will not hurt.
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.
@TimothyGu would you like to keep it to be on the safe side about this or shall I just remove the part again?
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.
@apapirovski Thanks for digging up the original PR. It was very informative. @BridgeAR Feel free to remove.
On Node.js 9.2.1 |
This shouldn't land on v9.x unless V8 6.3 makes its way there. |
@apapirovski I compared |
@lpinca Right, that makes sense. I assume @BridgeAR was talking about If this lands, it can probably land on both v8.x & v9.x because there doesn't seem to be a perf difference. |
I didn't test it but I assume current code is still faster when an error is passed. @apapirovski do you have some numbers at hand? |
I would guess that it definitely is. The question is (probably) whether we want to keep around this type of code or clean it up. I would guess that |
It makes sense. Reading the discussion in https://github.com/nodejs/node/pull/15025/files it shouldn't probably have been added in the first place. |
That is correct. |
Ping @lpinca @apapirovski @TimothyGu @jasnell @maclover7 what do you think? |
Seems good to me, but the |
FWIW according to https://v8project.blogspot.it/2017/12/v8-release-64.html the |
@lpinca that was the change that reminded me about it (https://chromium.googlesource.com/v8/v8.git/+/bcee140617fe90e8c354394216225615b9558113). I am going to check if this specific case is actually better with instanceof after 6.4 landed or if |
c61bb73
to
c4b51c1
Compare
So I just checked this again and the current solution is still faster on master. It is also faster on v.8 and v.9 but not on v.6. The performance divers depending on the input. But this is always faster than the current implementation. |
The commit message should be changed before this lands. |
Ping @lpinca @apapirovski @jasnell @TimothyGu @maclover7 PTAL |
Minor performance improvement.
c4b51c1
to
cc1eae9
Compare
CI before landing https://ci.nodejs.org/job/node-test-pull-request/13455/ |
Minor performance improvement. PR-URL: nodejs#17574 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Landed in b5825e1 |
Minor performance improvement. PR-URL: #17574 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Minor performance improvement. PR-URL: #17574 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Minor performance improvement. PR-URL: nodejs#17574 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Jon Moss <me@jonathanmoss.me> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Should this be backported to 8.x? If so, we need a separate backport PR. |
With newer V8 versions instanceof checks became very fast and
we do not have to check for the property existence anymore.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
assert