d8658177ba
In Promise.all we used to allocate a fresh closure plus a fresh context for each individual element, which is quite a lot of overhead, especially since this could be shared in a single context for all elements. The only bit of information that is needed for each resolve element closure is the index under which to store the resulting value. With this change we move this index to the "identity hash" field of the JSFunction, which doesn't care about the concrete value anyways, as long as it's not zero (the "no hash" sentinel), and share the rest of the fields in a single outer context for all resolve element closures. This limits the maximum number of elements for Promise.all to 2^21 for now, but that should be fine. Shall we ever see the need for more than this, we can add machinery to overflow to separate context for indices larger than 2^21. This significantly reduces the overhead due to Promise.all on the parallel-async-es2017-native test, with execution time dropping from around 148ms to 133ms, so overall a steady 10% improvement on this benchmark. Bug: v8:7253 Change-Id: I1092da771c4919f3db7129d2b0a244fc26a7b144 Reviewed-on: https://chromium-review.googlesource.com/973283 Reviewed-by: Yang Guo <yangguo@chromium.org> Reviewed-by: Benedikt Meurer <bmeurer@chromium.org> Commit-Queue: Benedikt Meurer <bmeurer@chromium.org> Cr-Commit-Position: refs/heads/master@{#52134}
20 lines
705 B
JavaScript
20 lines
705 B
JavaScript
// Copyright 2018 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
|
|
|
|
// Make sure we properly throw a RangeError when overflowing the maximum
|
|
// number of elements for Promise.all, which is capped at 2^21 bits right
|
|
// now, since we store the indices as identity hash on the resolve element
|
|
// closures.
|
|
const a = new Array(2 ** 21 - 1);
|
|
const p = Promise.resolve(1);
|
|
for (let i = 0; i < a.length; ++i) a[i] = p;
|
|
testAsync(assert => {
|
|
assert.plan(1);
|
|
Promise.all(a).then(assert.unreachable, reason => {
|
|
assert.equals(true, reason instanceof RangeError);
|
|
});
|
|
});
|