Commit 76ad3ab5 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[identity-map] Change resize heuristic

Change the resizing behaviour on insert to match that of the hash map
in base. Specifically, resize when hitting 80% occupancy.

Locally, I measure a ~6% improvement in serialization time from this
change.

Change-Id: I3fe84de39b2337859fe75fa6b3848198b82071ae
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2448798
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70324}
parent 95bb97bc
......@@ -64,24 +64,30 @@ int IdentityMapBase::ScanKeysFor(Address address, uint32_t hash) const {
std::pair<int, bool> IdentityMapBase::InsertKey(Address address,
uint32_t hash) {
DCHECK_EQ(gc_counter_, heap_->gc_count());
// Grow the map if we reached >= 80% occupancy.
if (size_ + size_ / 4 >= capacity_) {
Resize(capacity_ * kResizeFactor);
}
Address not_mapped = ReadOnlyRoots(heap_).not_mapped_symbol().ptr();
int start = hash & mask_;
// Guaranteed to terminate since size_ < capacity_, there must be at least
// one empty slot.
int index = start;
while (true) {
int start = hash & mask_;
int limit = capacity_ / 2;
// Search up to {limit} entries.
for (int index = start; --limit > 0; index = (index + 1) & mask_) {
if (keys_[index] == address) return {index, true}; // Found.
if (keys_[index] == not_mapped) { // Free entry.
size_++;
DCHECK_LE(size_, capacity_);
keys_[index] = address;
return {index, false};
}
if (keys_[index] == address) return {index, true}; // Found.
if (keys_[index] == not_mapped) { // Free entry.
size_++;
DCHECK_LE(size_, capacity_);
keys_[index] = address;
return {index, false};
}
// Should only have to resize once, since we grow 4x.
Resize(capacity_ * kResizeFactor);
index = (index + 1) & mask_;
// We should never loop back to the start.
DCHECK_NE(index, start);
}
UNREACHABLE();
}
bool IdentityMapBase::DeleteIndex(int index, uintptr_t* deleted_value) {
......
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