Use a stack-allocated buffer for when computing a small string hash.
Using a 256-byte buffer avoids 99% of allocations across v8's top25 benchmark. This also leads to a significant performance increase on speedometer, with a ~1.2% improvement on jQuery, ~1.3% on VanillaJS and an overall ~0.4% improvement on the score. Bug: v8:7555 Change-Id: Icd6fa07341eb989892431cb1e4995557e35c7a67 Reviewed-on: https://chromium-review.googlesource.com/971837 Commit-Queue: Lucas Gadani <lfg@chromium.org> Reviewed-by: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#52125}
This commit is contained in:
parent
9ca8d90b8b
commit
ab21ced5cd
@ -17096,12 +17096,22 @@ class StringTableNoAllocateKey : public StringTableKey {
|
||||
special_flattening_ = true;
|
||||
uint32_t hash_field = 0;
|
||||
if (one_byte_) {
|
||||
one_byte_content_ = new uint8_t[length];
|
||||
if (V8_LIKELY(length <=
|
||||
static_cast<int>(arraysize(one_byte_buffer_)))) {
|
||||
one_byte_content_ = one_byte_buffer_;
|
||||
} else {
|
||||
one_byte_content_ = new uint8_t[length];
|
||||
}
|
||||
String::WriteToFlat(string, one_byte_content_, 0, length);
|
||||
hash_field =
|
||||
StringHasher::HashSequentialString(one_byte_content_, length, seed);
|
||||
} else {
|
||||
two_byte_content_ = new uint16_t[length];
|
||||
if (V8_LIKELY(length <=
|
||||
static_cast<int>(arraysize(two_byte_buffer_)))) {
|
||||
two_byte_content_ = two_byte_buffer_;
|
||||
} else {
|
||||
two_byte_content_ = new uint16_t[length];
|
||||
}
|
||||
String::WriteToFlat(string, two_byte_content_, 0, length);
|
||||
hash_field =
|
||||
StringHasher::HashSequentialString(two_byte_content_, length, seed);
|
||||
@ -17119,9 +17129,9 @@ class StringTableNoAllocateKey : public StringTableKey {
|
||||
|
||||
~StringTableNoAllocateKey() {
|
||||
if (one_byte_) {
|
||||
delete[] one_byte_content_;
|
||||
if (one_byte_content_ != one_byte_buffer_) delete[] one_byte_content_;
|
||||
} else {
|
||||
delete[] two_byte_content_;
|
||||
if (two_byte_content_ != two_byte_buffer_) delete[] two_byte_content_;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17195,6 +17205,10 @@ class StringTableNoAllocateKey : public StringTableKey {
|
||||
uint8_t* one_byte_content_;
|
||||
uint16_t* two_byte_content_;
|
||||
};
|
||||
union {
|
||||
uint8_t one_byte_buffer_[256];
|
||||
uint16_t two_byte_buffer_[128];
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user