• Jaroslav Sevcik's avatar
    [turbofan] Load elimination - use maps to avoid state invalidation. · ea891e87
    Jaroslav Sevcik authored
    Currently, the transition elements kind operation invalidates the
    elements of all other arrays. In particular, if we loop over matrix 
    elements using two nested loops, and do possibly transitioning access 
    a[i][j] in every iteration, we invalidate the load elimination state 
    for the array 'a' because a[i][j] might transition elements kind 
    for the 'a[i]' array. As a result, the 'a[i]' access cannot be 
    hoisted from the inner loop.
    
    With this CL, we figure out that transitioning 'a[i]' cannot affect 'a'
    because we know that 'a' does not have the transition's source map.
    
    In the micro-benchmark below, the time for summing up the elements of
    100x100 matrix improves by factor of 1.7 (from ~340ms to ~190ms).
    
    function matrixSum(a) {
      let s = 0;
      let rowCount = a.length;
      let columnCount = a[0].length;
      for (let i = 0; i < rowCount; i++) {
        for (let j = 0; j < columnCount ; j++) {
          s += a[i][j];
        }
      }
      return s;
    }
    
    // Setup the matrices:
    // Smi elements.
    var ma = [[1, 2], [3, 4]];
    // Holey double elements.
    var b = Array(100);
    for (let i = 0; i < 100; i++) b[i] = 1.1;
    var mb = [];
    for (let i = 0; i < 100; i++) mb[i] = b;
    
    // Warmup.
    matrixSum(mb);
    matrixSum(mb);
    matrixSum(ma);
    matrixSum(mb);
    matrixSum(ma);
    
    %OptimizeFunctionOnNextCall(matrixSum);
    
    function runner(m) {
      let s = 0;
      for (let i = 0; i < 1e4; i++) {
        s += matrixSum(m);
      }
      return s;
    }
    // Make sure the runner does not know the elements kinds.
    %NeverOptimizeFunction(runner);
    
    // Measure.
    console.time("Sum");
    runner(mb);
    console.timeEnd("Sum");
    
    
    Bug: v8:6344
    Change-Id: Ie0642d8693ed63116b1aaed7d2f261fcb64729fe
    Reviewed-on: https://chromium-review.googlesource.com/704634
    Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
    Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#48334}
    ea891e87
load-elimination.cc 47.9 KB