68e4d86c6e
TurboFan wasn't able to inline calls to Array.prototype.push which didn't have exactly one parameter. This was a rather artifical limitation and was mostly due to the way the MaybeGrowFastElements operator was implemented (which was not ideal by itself). Refactoring this a bit, allows us to inline the operation in general, independent of the number of values to push. Array#push with multiple parameters is used quite a lot inside Ember (as discovered by Apple, i.e. https://bugs.webkit.org/show_bug.cgi?id=175823) and is also dominating the Six-Speed/SpreadLiterals/ES5 benchmark (see https://twitter.com/SpiderMonkeyJS/status/906528938452832257 from the SpiderMonkey folks). The micro-benchmark mentioned in the tracking bug (v8:6808) improves from arrayPush0: 2422 ms. arrayPush1: 2567 ms. arrayPush2: 4092 ms. arrayPush3: 4308 ms. to arrayPush0: 798 ms. arrayPush1: 2563 ms. arrayPush2: 2623 ms. arrayPush3: 2773 ms. with this change, effectively removing the odd 50-60% performance cliff that was associated with going from one parameter to two or more. Bug: v8:2229, v8:6808 Change-Id: Iffe4c1233903c04c3dc2062aad39d99769c8ab57 Reviewed-on: https://chromium-review.googlesource.com/657582 Reviewed-by: Jaroslav Sevcik <jarin@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#47940}
240 lines
5.5 KiB
JavaScript
240 lines
5.5 KiB
JavaScript
// Copyright 2017 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --allow-natives-syntax --opt
|
|
|
|
// Test multiple arguments push for PACKED_SMI_ELEMENTS.
|
|
(function() {
|
|
function push0(a) {
|
|
return a.push();
|
|
}
|
|
|
|
assertEquals(0, push0([]));
|
|
assertEquals(1, push0([1]));
|
|
%OptimizeFunctionOnNextCall(push0);
|
|
assertEquals(2, push0([1, 2]));
|
|
|
|
function push1(a) {
|
|
return a.push(1);
|
|
}
|
|
|
|
assertEquals(1, push1([]));
|
|
assertEquals(2, push1([1]));
|
|
%OptimizeFunctionOnNextCall(push1);
|
|
assertEquals(3, push1([1, 2]));
|
|
|
|
function push2(a) {
|
|
return a.push(1, 2);
|
|
}
|
|
|
|
assertEquals(2, push2([]));
|
|
assertEquals(3, push2([1]));
|
|
%OptimizeFunctionOnNextCall(push2);
|
|
assertEquals(4, push2([1, 2]));
|
|
|
|
function push3(a) {
|
|
return a.push(1, 2, 3);
|
|
}
|
|
|
|
assertEquals(3, push3([]));
|
|
assertEquals(4, push3([1]));
|
|
%OptimizeFunctionOnNextCall(push3);
|
|
assertEquals(5, push3([1, 2]));
|
|
})();
|
|
|
|
// Test multiple arguments push for HOLEY_SMI_ELEMENTS.
|
|
(function() {
|
|
function push0(a) {
|
|
return a.push();
|
|
}
|
|
|
|
assertEquals(1, push0(new Array(1)));
|
|
assertEquals(2, push0(new Array(2)));
|
|
%OptimizeFunctionOnNextCall(push0);
|
|
assertEquals(3, push0(new Array(3)));
|
|
|
|
function push1(a) {
|
|
return a.push(1);
|
|
}
|
|
|
|
assertEquals(2, push1(new Array(1)));
|
|
assertEquals(3, push1(new Array(2)));
|
|
%OptimizeFunctionOnNextCall(push1);
|
|
assertEquals(4, push1(new Array(3)));
|
|
|
|
function push2(a) {
|
|
return a.push(1, 2);
|
|
}
|
|
|
|
assertEquals(3, push2(new Array(1)));
|
|
assertEquals(4, push2(new Array(2)));
|
|
%OptimizeFunctionOnNextCall(push2);
|
|
assertEquals(5, push2(new Array(3)));
|
|
|
|
function push3(a) {
|
|
return a.push(1, 2, 3);
|
|
}
|
|
|
|
assertEquals(4, push3(new Array(1)));
|
|
assertEquals(5, push3(new Array(2)));
|
|
%OptimizeFunctionOnNextCall(push3);
|
|
assertEquals(6, push3(new Array(3)));
|
|
})();
|
|
|
|
// Test multiple arguments push for PACKED_DOUBLE_ELEMENTS.
|
|
(function() {
|
|
function push0(a) {
|
|
return a.push();
|
|
}
|
|
|
|
assertEquals(1, push0([1.1]));
|
|
assertEquals(2, push0([1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push0);
|
|
assertEquals(3, push0([1.1, 2.2, 3.3]));
|
|
|
|
function push1(a) {
|
|
return a.push(1.1);
|
|
}
|
|
|
|
assertEquals(2, push1([1.1]));
|
|
assertEquals(3, push1([1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push1);
|
|
assertEquals(4, push1([1.1, 2.2, 3.3]));
|
|
|
|
function push2(a) {
|
|
return a.push(1.1, 2.2);
|
|
}
|
|
|
|
assertEquals(3, push2([1.1]));
|
|
assertEquals(4, push2([1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push2);
|
|
assertEquals(5, push2([1.1, 2.2, 3.3]));
|
|
|
|
function push3(a) {
|
|
return a.push(1.1, 2.2, 3.3);
|
|
}
|
|
|
|
assertEquals(4, push3([1.1]));
|
|
assertEquals(5, push3([1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push3);
|
|
assertEquals(6, push3([1.1, 2.2, 3.3]));
|
|
})();
|
|
|
|
// Test multiple arguments push for HOLEY_DOUBLE_ELEMENTS.
|
|
(function() {
|
|
function push0(a) {
|
|
return a.push();
|
|
}
|
|
|
|
assertEquals(2, push0([, 1.1]));
|
|
assertEquals(3, push0([, 1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push0);
|
|
assertEquals(4, push0([, 1.1, 2.2, 3.3]));
|
|
|
|
function push1(a) {
|
|
return a.push(1.1);
|
|
}
|
|
|
|
assertEquals(3, push1([, 1.1]));
|
|
assertEquals(4, push1([, 1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push1);
|
|
assertEquals(5, push1([, 1.1, 2.2, 3.3]));
|
|
|
|
function push2(a) {
|
|
return a.push(1.1, 2.2);
|
|
}
|
|
|
|
assertEquals(4, push2([, 1.1]));
|
|
assertEquals(5, push2([, 1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push2);
|
|
assertEquals(6, push2([, 1.1, 2.2, 3.3]));
|
|
|
|
function push3(a) {
|
|
return a.push(1.1, 2.2, 3.3);
|
|
}
|
|
|
|
assertEquals(5, push3([, 1.1]));
|
|
assertEquals(6, push3([, 1.1, 2.2]));
|
|
%OptimizeFunctionOnNextCall(push3);
|
|
assertEquals(7, push3([, 1.1, 2.2, 3.3]));
|
|
})();
|
|
|
|
// Test multiple arguments push for PACKED_ELEMENTS.
|
|
(function() {
|
|
function push0(a) {
|
|
return a.push();
|
|
}
|
|
|
|
assertEquals(1, push0(['1']));
|
|
assertEquals(2, push0(['1', '2']));
|
|
%OptimizeFunctionOnNextCall(push0);
|
|
assertEquals(3, push0(['1', '2', '3']));
|
|
|
|
function push1(a) {
|
|
return a.push('1');
|
|
}
|
|
|
|
assertEquals(2, push1(['1']));
|
|
assertEquals(3, push1(['1', '2']));
|
|
%OptimizeFunctionOnNextCall(push1);
|
|
assertEquals(4, push1(['1', '2', '3']));
|
|
|
|
function push2(a) {
|
|
return a.push('1', '2');
|
|
}
|
|
|
|
assertEquals(3, push2(['1']));
|
|
assertEquals(4, push2(['1', '2']));
|
|
%OptimizeFunctionOnNextCall(push2);
|
|
assertEquals(5, push2(['1', '2', '3']));
|
|
|
|
function push3(a) {
|
|
return a.push('1', '2', '3');
|
|
}
|
|
|
|
assertEquals(4, push3(['1']));
|
|
assertEquals(5, push3(['1', '2']));
|
|
%OptimizeFunctionOnNextCall(push3);
|
|
assertEquals(6, push3(['1', '2', '3']));
|
|
})();
|
|
|
|
// Test multiple arguments push for HOLEY_ELEMENTS.
|
|
(function() {
|
|
function push0(a) {
|
|
return a.push();
|
|
}
|
|
|
|
assertEquals(2, push0([, '1']));
|
|
assertEquals(3, push0([, '1', '2']));
|
|
%OptimizeFunctionOnNextCall(push0);
|
|
assertEquals(4, push0([, '1', '2', '3']));
|
|
|
|
function push1(a) {
|
|
return a.push('1');
|
|
}
|
|
|
|
assertEquals(3, push1([, '1']));
|
|
assertEquals(4, push1([, '1', '2']));
|
|
%OptimizeFunctionOnNextCall(push1);
|
|
assertEquals(5, push1([, '1', '2', '3']));
|
|
|
|
function push2(a) {
|
|
return a.push('1', '2');
|
|
}
|
|
|
|
assertEquals(4, push2([, '1']));
|
|
assertEquals(5, push2([, '1', '2']));
|
|
%OptimizeFunctionOnNextCall(push2);
|
|
assertEquals(6, push2([, '1', '2', '3']));
|
|
|
|
function push3(a) {
|
|
return a.push('1', '2', '3');
|
|
}
|
|
|
|
assertEquals(5, push3([, '1']));
|
|
assertEquals(6, push3([, '1', '2']));
|
|
%OptimizeFunctionOnNextCall(push3);
|
|
assertEquals(7, push3([, '1', '2', '3']));
|
|
})();
|