Commit c68f7194 authored by rmcilroy's avatar rmcilroy Committed by Commit bot

Use a better hash function in IdentityMap.

Reduces time for ConstantArrayBuilderTest.AllocateAllEntries from 21000ms to 106ms in
debug mode.

BUG=v8:4280
LOG=N

Review URL: https://codereview.chromium.org/1696363002

Cr-Commit-Position: refs/heads/master@{#34038}
parent 8f87c0ac
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "src/identity-map.h" #include "src/identity-map.h"
#include "src/heap/heap.h" #include "src/base/functional.h"
#include "src/heap/heap-inl.h" #include "src/heap/heap-inl.h"
#include "src/zone-containers.h" #include "src/zone-containers.h"
...@@ -42,8 +42,7 @@ IdentityMapBase::RawEntry IdentityMapBase::Insert(Object* key) { ...@@ -42,8 +42,7 @@ IdentityMapBase::RawEntry IdentityMapBase::Insert(Object* key) {
int IdentityMapBase::Hash(Object* address) { int IdentityMapBase::Hash(Object* address) {
CHECK_NE(address, heap_->not_mapped_symbol()); CHECK_NE(address, heap_->not_mapped_symbol());
uintptr_t raw_address = reinterpret_cast<uintptr_t>(address); uintptr_t raw_address = reinterpret_cast<uintptr_t>(address);
// Xor some of the upper bits, since the lower 2 or 3 are usually aligned. return static_cast<int>(hasher_(raw_address));
return static_cast<int>((raw_address >> 11) ^ raw_address);
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#ifndef V8_IDENTITY_MAP_H_ #ifndef V8_IDENTITY_MAP_H_
#define V8_IDENTITY_MAP_H_ #define V8_IDENTITY_MAP_H_
#include "src/base/functional.h"
#include "src/handles.h" #include "src/handles.h"
namespace v8 { namespace v8 {
...@@ -48,6 +49,7 @@ class IdentityMapBase { ...@@ -48,6 +49,7 @@ class IdentityMapBase {
RawEntry Insert(Object* key); RawEntry Insert(Object* key);
int Hash(Object* address); int Hash(Object* address);
base::hash<uintptr_t> hasher_;
Heap* heap_; Heap* heap_;
Zone* zone_; Zone* zone_;
int gc_counter_; int gc_counter_;
......
...@@ -33,13 +33,11 @@ STATIC_CONST_MEMBER_DEFINITION const size_t ...@@ -33,13 +33,11 @@ STATIC_CONST_MEMBER_DEFINITION const size_t
TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) { TEST_F(ConstantArrayBuilderTest, AllocateAllEntries) {
ConstantArrayBuilder builder(isolate(), zone()); ConstantArrayBuilder builder(isolate(), zone());
for (size_t i = 0; i < kMaxCapacity; i++) { for (size_t i = 0; i < kMaxCapacity; i++) {
Handle<Object> object = isolate()->factory()->NewNumberFromSize(i); builder.Insert(handle(Smi::FromInt(static_cast<int>(i)), isolate()));
builder.Insert(object);
CHECK_EQ(builder.size(), i + 1);
CHECK(builder.At(i)->SameValue(*object));
} }
CHECK_EQ(builder.size(), kMaxCapacity);
for (size_t i = 0; i < kMaxCapacity; i++) { for (size_t i = 0; i < kMaxCapacity; i++) {
CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), static_cast<double>(i)); CHECK_EQ(Handle<Smi>::cast(builder.At(i))->value(), i);
} }
} }
......
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