DescriptionArray.prototype.reverse should call [[HasProperty]] on elements before [[Get]]
This is a change from ES5 to ES6: When reversing an array, first it is checked
whether the element exists, before the element is looked up. The order in ES6
is
[[HasElement]] lower
[[Get]] lower (if present)
[[HasElement]] upper
[[Get]] upper (if present)
In ES5, on the other hand, the order was
[[Get]] lower
[[Get]] upper
[[HasElement]] lower
[[HasElement]] upper
To mitigate the performance impact, this patch implements a new, third copy
of reversing arrays if %_HasPackedElements. This allows us to skip all
membership tests, and a quick and dirty benchmark shows that the new version
is faster:
Over 4 runs, the slowest for the new version:
d8> var start = Date.now(); for (var i = 0; i < 100000000; i++) [1, 2, 3, 4, 5].reverse(); Date.now() - start
4658
Over 3 runs, the fastest for the old version:
d8> var start = Date.now(); for (var i = 0; i < 100000000; i++) [1, 2, 3, 4, 5].reverse(); Date.now() - start
5176
BUG=v8:4223
R=adamk
LOG=Y
Committed: https://crrev.com/f76dfee9dfa56a0a3ca3c95d17c244cd5cc6753d
Cr-Commit-Position: refs/heads/master@{#29716}
Patch Set 1 #Patch Set 2 : Add faster PackedArrayReverse #Patch Set 3 : Add packed implementation #
Total comments: 8
Patch Set 4 : Changes from code review #
Messages
Total messages: 18 (3 generated)
|