-
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
Performance regression of instanceof in v7 and master #9634
Comments
Could you also create a V8 bug and link to it here ? |
@targos done, thanks. |
I cannot reproduce this regression in Chrome 54. |
Now that I test it... neither can I, and in theory they use the same v8 version. |
Found the cause: commit 2a4b068 from last September, cc @addaleax. Chrome 54 ships the exact same version as node.js master, 5.4.500.41, and I can confirm that it's fast in Chrome and d8 ( I checked with perf(1) and it showed that V8 was spending a phenomenal amount of time in function F() {}
const hasInstance = Function.prototype[Symbol.hasInstance];
Object.defineProperty(F, Symbol.hasInstance, { value: hasInstance });
for (var o = {}, i = 0; i < 1e8; i++) o instanceof Object; Basically, if V8 sees that @@hasInstance is used, it starts emitting conservative slow path code. |
Oh no! :( We have some possible solutions: a. revert that fix, but probably it's semver-major. If we could do it semver-minor it will be the best solution. It would be nice to a quick post-mortem on this one. How can we spot those before releasing? |
Huh… yeah, I did not see that coming. |
(sorry, mis-clicked and posted the comment too early)
|
I found out that https://github.com/mcollina/bloomrun was 10 times slower in v7 rather than v6. It boiled down to |
Truthfully, I didn't bisect. I had a pretty good idea from looking at the perf data where the problem came from and reverting the commit confirmed that. :-) |
I think I can come up with a small(ish) mitigation for the problem. Let me have a look. |
In Crankshaft we can actually do an abstract interpretation of the @@hasInstance lookup when optimizing instanceof and then use the normal machinery to protect the result instead of relying on the global @@hasInstance protector cell for optimizations. This recovers the 100x performance drop in Node.js v7 reported in nodejs/node#9634. This patch should be easily back-mergable to Node.js v7. BUG=v8:5640 R=yangguo@chromium.org,franzih@chromium.org Review-Url: https://codereview.chromium.org/2504263004 Cr-Commit-Position: refs/heads/master@{#41059}
@bmeurer I can confirm the patch works as expected, and it's fairly straightforward to apply. |
@mcollina Awesome. I'm currently fixing the issue in TurboFan as well. The patch is slightly more involved there for a couple of reasons. But you should be fine with the Crankshaft fix for 99% of the cases. |
About that, I wonder: is TurboFan enabled by default in V8? If so, how do we know what parts of it are shipped without a flag? I'm asking because I think I never saw a |
It is for language features that Crankshaft cannot deal with, i.e. try-catch, try-finally, for-of, etc. |
Would this have been caught by an octane run ? If so it might make sense to set that up as one of our nightly benchmarks. Now that we have our own v8 branch were all of the changes applied I'm guessing it should re relatively easy to do that. |
I did a quick check with the EarleyBoyer benchmark, it has a lot of instanceof checks. Before/after numbers when run in node (not d8):
So an unequivocal 'yes' in this particular case. :-) |
Will look at getting octane added as part of our nightly benchmarks in nodejs/benchmarking#75. |
Good idea! |
The issue is marked as fixed in v8. Can we backport the fix here? What is the process for v8 patches and backports? |
@fhinkel any chance for it to be backported to V8 5.4 or 5.5 ? |
@natorion Can we backport performance improvements to 5.4 or only bug fixes? If we can't backport it to V8, we can always cherry-pick the commits to Node. We probably want to wait a few days though, in case there are any issues with the commits. |
For 5.4 it is probably to late. For 5.5 it should be fine (the CS part) as this is still in beta. Need to check though. What is the benefit for Node if this is merged to 5.5 though? BTW, this also needs to be fixed on 5.6. |
Should we wait until #9697 has landed? |
We need to get this into node v7. |
We will probably upgrade to V8 5.5 during the v7 release cycle if we can work out the kinks, see #9618. |
Orignial commit message: [crankshaft] No need to rely on the @@hasInstance protector. In Crankshaft we can actually do an abstract interpretation of the @@hasInstance lookup when optimizing instanceof and then use the normal machinery to protect the result instead of relying on the global @@hasInstance protector cell for optimizations. This recovers the 100x performance drop in Node.js v7 reported in nodejs#9634. This patch should be easily back-mergable to Node.js v7. BUG=v8:5640 R=yangguo@chromium.org,franzih@chromium.org Committed: https://crrev.com/08377af957b1602396ebf3e11ae000f15ed09333 Cr-Commit-Position: refs/heads/master@{nodejs#41059} Fixes: nodejs#9634
Orignial commit message: [crankshaft] No need to rely on the @@hasInstance protector. In Crankshaft we can actually do an abstract interpretation of the @@hasInstance lookup when optimizing instanceof and then use the normal machinery to protect the result instead of relying on the global @@hasInstance protector cell for optimizations. This recovers the 100x performance drop in Node.js v7 reported in #9634. This patch should be easily back-mergable to Node.js v7. BUG=v8:5640 R=yangguo@chromium.org,franzih@chromium.org Committed: https://crrev.com/08377af957b1602396ebf3e11ae000f15ed09333 Cr-Commit-Position: refs/heads/master@{#41059} PR-URL: #9730 Fixes: #9634 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Orignial commit message: [crankshaft] No need to rely on the @@hasInstance protector. In Crankshaft we can actually do an abstract interpretation of the @@hasInstance lookup when optimizing instanceof and then use the normal machinery to protect the result instead of relying on the global @@hasInstance protector cell for optimizations. This recovers the 100x performance drop in Node.js v7 reported in nodejs#9634. This patch should be easily back-mergable to Node.js v7. BUG=v8:5640 R=yangguo@chromium.org,franzih@chromium.org Committed: https://crrev.com/08377af957b1602396ebf3e11ae000f15ed09333 Cr-Commit-Position: refs/heads/master@{nodejs#41059} PR-URL: nodejs#9730 Fixes: nodejs#9634 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Node 7.x contains a performance regression which makes certain `instanceof` tests 100x slower: nodejs/node#9634 Upgrading `should` from 8.3.0 to 11.1.2 makes this performance problem go away when running our tests, for reasons I don't fully understand, but it seems to be related to: shouldjs/should.js@0737171 so perhaps the root of the performance problem is actually `should.not`, not the `instanceof` regression.
It looks like this might have regressed back to a 50(ish)x slowdown for System: Linux 4.9.11 x86_64
|
@bengl Yes, that seems like a good idea (and ping nodejs/v8 in it:)) |
This is https://bugs.chromium.org/p/v8/issues/detail?id=5902 I'll merge this on Monday to 5.8. |
Merged to V8 version 5.8: https://chromium.googlesource.com/v8/v8.git/+/e62656ffe685408e06d175ff5f371c8fd2556b58 |
@hashseed fantastic! |
instanceof
checks has become almost 100 times slower in Node v7+ (and current master)In node v6:
In node v7:
I know this is a problem in V8, but I think it's good to track it here as well.
v8 issue: https://bugs.chromium.org/p/v8/issues/detail?id=5640
cc @fhinkel
The text was updated successfully, but these errors were encountered: