perf(Subscription): use instanceof to avoid megamorphic LoadIC - #4499
Merged
Merged
Conversation
Pull Request Test Coverage Report for Build 7965
💛 - Coveralls |
bmeurer
force-pushed
the
perf_Subscription_add
branch
from
January 28, 2019 15:08
77c1016 to
20053d4
Compare
In `Subscription#add()` use `instanceof` to test whether `subscription` must be wrapped in a `Subscription` (aka for presence of `_addParent` method), instead of `typeof subscription._addParent === 'function'`, as the latter is going to turn into a *megamorphic property access* in any realistic application and cause quite a bit of contention on the megamorphic stub cache in Node (aka V8). The `instanceof` is definitely faster, even if the property access would hit the megamorphic stub cache. For example in the case of a simple [Angular Universal prerender][1] test, just changing this can reduce the number of megamorphic stub cache misses by around **2%**. Even in the case where the megamorphic stub cache hits all the time, using `instanceof` is still faster. I put together a little micro- benchmark [here][2]. Running this with the latest V8 we get: ``` $ out/Release/d8 bench-instanceof-versus-typeof-megamorphic.js instanceOf: 91 ms. typeOf: 138 ms. ``` [1]: https://gist.githubusercontent.com/bmeurer/5b9480ef1a74c5187180193abc73dcd4/raw/fc5d9a01a6b7fe841efa1c7773ae55e70435d16a/prerender.js [2]: https://gist.github.com/bmeurer/d6d8d4e5d3a9937499ed738c93b3b7cf
bmeurer
force-pushed
the
perf_Subscription_add
branch
from
January 28, 2019 15:12
20053d4 to
03fa8e8
Compare
benlesh
approved these changes
Jan 29, 2019
Member
|
Thanks, @bmeurer!!! |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
Subscription#add()useinstanceofto test whethersubscriptionmust be wrapped in a
Subscription(aka for presence of_addParentmethod), instead of
typeof subscription._addParent === 'function',as the latter is going to turn into a megamorphic property access
in any realistic application and cause quite a bit of contention on
the megamorphic stub cache in Node (aka V8).
The
instanceofis definitely faster, even if the property accesswould hit the megamorphic stub cache. For example in the case of a
simple Angular Universal prerender test, just changing this can
reduce the number of megamorphic stub cache misses by around 2%.
Even in the case where the megamorphic stub cache hits all the time,
using
instanceofis still faster. I put together a little micro-benchmark here. Running this with the latest V8 we get: