• littledan's avatar
    Array.prototype.reverse should call [[HasProperty]] on elements before [[Get]] · f76dfee9
    littledan authored
    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
    
    Review URL: https://codereview.chromium.org/1238593003
    
    Cr-Commit-Position: refs/heads/master@{#29716}
    f76dfee9
Name
Last commit
Last update
benchmarks Loading commit data...
build Loading commit data...
include Loading commit data...
infra Loading commit data...
samples Loading commit data...
src Loading commit data...
test Loading commit data...
testing Loading commit data...
third_party/binutils Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.gitignore Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind Loading commit data...
Makefile Loading commit data...
Makefile.android Loading commit data...
Makefile.nacl Loading commit data...
OWNERS Loading commit data...
PRESUBMIT.py Loading commit data...
README.md Loading commit data...
WATCHLISTS Loading commit data...
codereview.settings Loading commit data...