Skip to content

Commit 9baa561

Browse files
ofrobotsMyles Borins
authored and
Myles Borins
committed
deps: backport 066747e from upstream V8
This backport fixes a performance pathology in how arrays grow/shrink. Fixes: #3538 V8-Commit: v8/v8@066747e PR-URL: #4625 Reviewed-By: cjihrig - Colin Ihrig <[email protected]> Reviewed-By: targos - Michaël Zasso <[email protected]> Reviewed-By: indutny - Fedor Indutny <[email protected]> Original commit message: Make sure that NormalizeElements and ShouldConvertToFastElements are … …based on the same values BUG=v8:4518 LOG=n Review URL: https://codereview.chromium.org/1472293002 Cr-Commit-Position: refs/heads/master@{#32265} Commit metadata for v4.x-staging: PR-URL: #4655 Reviewed-By: James M Snell <[email protected]>
1 parent f5bfacd commit 9baa561

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

deps/v8/src/elements.cc

+11-6
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,18 @@ class FastElementsAccessor
11001100
}
11011101
int num_used = 0;
11021102
for (int i = 0; i < backing_store->length(); ++i) {
1103-
if (!backing_store->is_the_hole(i)) ++num_used;
1104-
// Bail out early if more than 1/4 is used.
1105-
if (4 * num_used > backing_store->length()) break;
1106-
}
1107-
if (4 * num_used <= backing_store->length()) {
1108-
JSObject::NormalizeElements(obj);
1103+
if (!backing_store->is_the_hole(i)) {
1104+
++num_used;
1105+
// Bail out if a number dictionary wouldn't be able to save at least
1106+
// 75% space.
1107+
if (4 * SeededNumberDictionary::ComputeCapacity(num_used) *
1108+
SeededNumberDictionary::kEntrySize >
1109+
backing_store->length()) {
1110+
return;
1111+
}
1112+
}
11091113
}
1114+
JSObject::NormalizeElements(obj);
11101115
}
11111116
}
11121117

deps/v8/src/objects.cc

+2
Original file line numberDiff line numberDiff line change
@@ -12459,6 +12459,8 @@ static bool ShouldConvertToFastElements(JSObject* object,
1245912459

1246012460
uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) *
1246112461
SeededNumberDictionary::kEntrySize;
12462+
12463+
// Turn fast if the dictionary only saves 50% space.
1246212464
return 2 * dictionary_size >= *new_capacity;
1246312465
}
1246412466

0 commit comments

Comments
 (0)