Skip to content

Commit 7ccce42

Browse files
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 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}
1 parent 138e1e5 commit 7ccce42

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
@@ -1071,13 +1071,18 @@ class FastElementsAccessor
10711071
}
10721072
int num_used = 0;
10731073
for (int i = 0; i < backing_store->length(); ++i) {
1074-
if (!backing_store->is_the_hole(i)) ++num_used;
1075-
// Bail out early if more than 1/4 is used.
1076-
if (4 * num_used > backing_store->length()) break;
1077-
}
1078-
if (4 * num_used <= backing_store->length()) {
1079-
JSObject::NormalizeElements(obj);
1074+
if (!backing_store->is_the_hole(i)) {
1075+
++num_used;
1076+
// Bail out if a number dictionary wouldn't be able to save at least
1077+
// 75% space.
1078+
if (4 * SeededNumberDictionary::ComputeCapacity(num_used) *
1079+
SeededNumberDictionary::kEntrySize >
1080+
backing_store->length()) {
1081+
return;
1082+
}
1083+
}
10801084
}
1085+
JSObject::NormalizeElements(obj);
10811086
}
10821087
}
10831088

deps/v8/src/objects.cc

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

1222712227
uint32_t dictionary_size = static_cast<uint32_t>(dictionary->Capacity()) *
1222812228
SeededNumberDictionary::kEntrySize;
12229+
12230+
// Turn fast if the dictionary only saves 50% space.
1222912231
return 2 * dictionary_size >= *new_capacity;
1223012232
}
1223112233

0 commit comments

Comments
 (0)