• Jaroslav Sevcik's avatar
    [turbofan] Optimize array destructuring · 3fe7d698
    Jaroslav Sevcik authored
    This CL introduces type narrowing and constant folding reducers
    to constant fold code that comes out of inlined destructuring
    of arrays. In particular, array iterator introduces code that
    contains a phi of a temporary array that blocks escape analysis.
    The phi comes from conditional that can be evaluated statically
    (i.e., constant folded), so with better constant folding we
    allow escape analysis to get rid of the temporary array.
    
    On a quick micro-benchmark below, we see more than 6x improvement.
    This is close to the hand-optimized version - if we replace
    body of f with 'return b + a', we get 220ms (versus 218ms with
    destructuring).
    
    function f(a, b) {
      [b, a] = [a, b];
      return a + b;
    }
    
    function sum(count) {
      let s = 0;
      for (let i = 0; i < count; i++) {
        s += f(1, 2);
      }
      return s;
    }
    
    // Warm up
    sum(1e5); sum(1e5);
    console.time("destructure array");
    sum(1e8);
    console.timeEnd("destructure array");
    
    console.timeEnd: destructure array, 213.526000
    
    console.timeEnd: destructure array, 1503.537000
    
    Bug: v8:7728
    Change-Id: Ib7aec1d5897989e6adb1af1eddd516d8b3866db5
    Reviewed-on: https://chromium-review.googlesource.com/1047672Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
    Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#53048}
    3fe7d698
Name
Last commit
Last update
benchmarks Loading commit data...
build_overrides Loading commit data...
docs Loading commit data...
gni 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 Loading commit data...
tools Loading commit data...
.clang-format Loading commit data...
.editorconfig Loading commit data...
.git-blame-ignore-revs Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gn Loading commit data...
.vpython Loading commit data...
.ycm_extra_conf.py Loading commit data...
AUTHORS Loading commit data...
BUILD.gn Loading commit data...
CODE_OF_CONDUCT.md Loading commit data...
ChangeLog Loading commit data...
DEPS Loading commit data...
LICENSE Loading commit data...
LICENSE.fdlibm Loading commit data...
LICENSE.strongtalk Loading commit data...
LICENSE.v8 Loading commit data...
LICENSE.valgrind 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...
snapshot_toolchain.gni Loading commit data...