Commit dcbd5234 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[runtime] The return of the StringTable shrinking

This CL fixes a bug where we would accidentally shrink to the same size of
the StringTable causing repeated unecessary allocations.

Bug: v8:5443, chromium:818642
Change-Id: I353b179616d5293f6d7143e7381ae6711343a835
Reviewed-on: https://chromium-review.googlesource.com/1044207Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53012}
parent 1a9034e2
......@@ -16671,18 +16671,17 @@ Handle<Derived> HashTable<Derived, Shape>::Shrink(Handle<Derived> table,
// there is extra room in the dictionary for additions. Don't go lower than
// room for {kMinShrinkCapacity} elements.
int at_least_room_for = nof + additionalCapacity;
DCHECK_LE(at_least_room_for, capacity);
if (at_least_room_for < Derived::kMinShrinkCapacity) return table;
int new_capacity = ComputeCapacity(at_least_room_for);
if (new_capacity < Derived::kMinShrinkCapacity) return table;
if (new_capacity == capacity) return table;
Isolate* isolate = table->GetIsolate();
const int kMinCapacityForPretenure = 256;
bool pretenure =
(at_least_room_for > kMinCapacityForPretenure) &&
bool pretenure = (at_least_room_for > kMinCapacityForPretenure) &&
!isolate->heap()->InNewSpace(*table);
Handle<Derived> new_table = HashTable::New(
isolate,
at_least_room_for,
pretenure ? TENURED : NOT_TENURED);
Handle<Derived> new_table =
HashTable::New(isolate, new_capacity, pretenure ? TENURED : NOT_TENURED,
USE_CUSTOM_MINIMUM_CAPACITY);
table->Rehash(*new_table);
return new_table;
......@@ -17215,10 +17214,9 @@ Handle<StringTable> StringTable::CautiousShrink(Handle<StringTable> table) {
int nof = table->NumberOfElements();
if (capacity <= StringTable::kMinCapacity) return table;
if (nof > (capacity / kMaxEmptyFactor)) return table;
// Make sure that after shrinking the table is half empty (aka. has capacity
// for another {nof} elements).
DCHECK_LE(nof * 2, capacity);
return Shrink(table, nof);
// Keep capacity for at least half of the current nof elements.
int slack_capacity = nof >> 2;
return Shrink(table, slack_capacity);
}
namespace {
......
......@@ -79,7 +79,7 @@ class StringTable : public HashTable<StringTable, StringTableShape> {
DECL_CAST(StringTable)
static const int kMaxEmptyFactor = 8;
static const int kMaxEmptyFactor = 4;
static const int kMinCapacity = 2048;
static const int kMinShrinkCapacity = kMinCapacity;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment