DescriptionOptimize @@species based on a global 'protector' cell
This patch makes ArraySpeciesCreate fast in V8 by avoiding two property reads
when the following conditions are met:
- No Array instance has had its __proto__ reset
- No Array instance has had a constructor property defined
- Array.prototype has not had its constructor changed
- Array[Symbol.species] has not been reset
For subclasses of Array, or for conditions where one of these assumptions is
violated, the full lookup of species is done according to the ArraySpeciesCreate
algorithm. Although this is a "performance cliff", it does not come up in the
expected typical use case of @@species (Array subclassing), so it is hoped that
this can form a good start. Array subclasses will incur the slowness of looking
up @@species, but their use won't slow down invocations of, for example,
Array.prototype.slice on Array base class instances.
Possible future optimizations:
- For the fallback case where the assumptions don't hold, optimize the two
property lookups.
- For Array.prototype.slice and Array.prototype.splice, even if the full lookup
of @@species needs to take place, we still could take the rest of the C++
fastpath. However, to do this correctly requires changing the calling convention
from C++ to JS to pass the @@species out, so it is not attempted in this patch.
With this patch, microbenchmarks of Array.prototype.slice do not suffer a
noticeable performance regression, unlike their previous 2.5x penalty.
TBR=hpayer@chromium.org
Committed: https://crrev.com/7033ae511f3cca7e5464353e80acbba645e07c44
Cr-Commit-Position: refs/heads/master@{#34199}
Patch Set 1 #Patch Set 2 : Starting tracking the relevant changes #Patch Set 3 : Complete first draft #Patch Set 4 : It passes the tests! #Patch Set 5 : Everything works now, and the fastpath gets taken for Array.prototype.slice! #Patch Set 6 : avoid taking splice slow path #Patch Set 7 : Fix message bug #Patch Set 8 : Rebase #
Total comments: 8
Patch Set 9 : Disallow heap GC #Patch Set 10 : DCHECK #
Total comments: 5
Patch Set 11 : Cleanup suggested by cbruni, and include deletions as they are needed #Patch Set 12 : Remove blank lines #
Messages
Total messages: 57 (26 generated)
|