Commit c4406c06 authored by Adenilson Cavalcanti's avatar Adenilson Cavalcanti Committed by Commit Bot

Updating ShapeCache hash function

Blink is using a suboptimal hash function both in hashing quality (i.e. collisions)
as also in speed as since 2004 new and faster hash functions were developed.

Based on testing on ARMv7 and x86, CityHash seems like a good alternative based on
both performance, portability and quality. For further data:
https://aras-p.info/blog/2016/08/09/More-Hash-Function-Tests/

We should consider next adding xxHash as it performed better on AArch64.

Bug: 735674
Change-Id: I8c7ccf2d834a42a9fcb01e2cc80ecda1e1c01772
Reviewed-on: https://chromium-review.googlesource.com/c/1311798Reviewed-by: default avatarEmil A Eklund <eae@chromium.org>
Commit-Queue: Adenilson Cavalcanti <cavalcantii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#604794}
parent 8a3f8667
...@@ -1465,6 +1465,11 @@ jumbo_component("platform") { ...@@ -1465,6 +1465,11 @@ jumbo_component("platform") {
"//ui/gfx/geometry", "//ui/gfx/geometry",
] ]
# This is faster on armv7, untested on other CPUs (e.g. mips, power, etc).
# TODO(cavalcantii): add next xxhash.
defines = [ "USE_FUNCTION_CITYHASH" ]
deps += [ "//third_party/smhasher:cityhash" ]
if (is_mac) { if (is_mac) {
sources -= [ sources -= [
"fonts/skia/font_cache_skia.cc", "fonts/skia/font_cache_skia.cc",
......
...@@ -30,13 +30,17 @@ ...@@ -30,13 +30,17 @@
#include "third_party/blink/renderer/platform/fonts/shaping/shape_cache.h" #include "third_party/blink/renderer/platform/fonts/shaping/shape_cache.h"
#include "third_party/blink/renderer/platform/wtf/string_hasher.h" #include "third_party/blink/renderer/platform/wtf/string_hasher.h"
#if defined(USE_FUNCTION_CITYHASH)
#include "third_party/smhasher/src/City.h"
#endif
namespace blink { namespace blink {
void ShapeCache::SmallStringKey::HashString() { void ShapeCache::SmallStringKey::HashString() {
// TODO(cavalcantii): replace this for a better hash function, // TODO(cavalcanti): next add xxhash.
// see crbug.com/735674. #if defined(USE_FUNCTION_CITYHASH)
hash_ = StringHasher::ComputeHash(characters_, length_); hash_ = CityHash64((const char*)characters_, length_ * sizeof(UChar));
#endif
} }
} // namespace blink } // namespace blink
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