[vm] Load canonical sets with spare capacity so a few inserts can happen during startup without trigging a rehash.

TEST=assert
Change-Id: I0cc09604a81fdfcc2bc6cd05c4748a2a8e161262
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214314
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2021-09-27 22:01:43 +00:00 committed by commit-bot@chromium.org
parent 76d874b171
commit bb21c8c02d
2 changed files with 14 additions and 4 deletions

View file

@ -534,6 +534,12 @@ class CanonicalSetSerializationCluster : public SerializationCluster {
required_capacity++;
}
}
// Over-allocate capacity so a few inserts can happen at startup without
// causing a rehash.
const intptr_t kSpareCapacity = 32;
required_capacity = static_cast<intptr_t>(
static_cast<double>(required_capacity + kSpareCapacity) /
HashTables::kMaxLoadFactor);
intptr_t num_occupied = 0;
@ -5365,6 +5371,10 @@ class StringDeserializationCluster
if (d->isolate_group() == Dart::vm_isolate_group()) {
Symbols::InitFromSnapshot(d->isolate_group());
}
#if defined(DEBUG)
Symbols::New(Thread::Current(), ":some:new:symbol:");
ASSERT(object_store->symbol_table() == table_.ptr()); // Did not rehash.
#endif
}
}
};

View file

@ -553,6 +553,8 @@ class HashTables : public AllStatic {
}
}
static constexpr double kMaxLoadFactor = 0.71;
template <typename Table>
static void EnsureLoadFactor(double high, const Table& table) {
// We count deleted elements because they take up space just
@ -707,8 +709,7 @@ class HashMap : public BaseIterTable {
protected:
void EnsureCapacity() const {
static const double kMaxLoadFactor = 0.71;
HashTables::EnsureLoadFactor(kMaxLoadFactor, *this);
HashTables::EnsureLoadFactor(HashTables::kMaxLoadFactor, *this);
}
};
@ -793,8 +794,7 @@ class HashSet : public BaseIterTable {
protected:
void EnsureCapacity() const {
static const double kMaxLoadFactor = 0.71;
HashTables::EnsureLoadFactor(kMaxLoadFactor, *this);
HashTables::EnsureLoadFactor(HashTables::kMaxLoadFactor, *this);
}
};