Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4859)

Unified Diff: base/memory/address_hasher.cc

Issue 2654073002: base: Introduce SharedMemoryTracker for POSIX (but not macOS) (Closed)
Patch Set: Use AddressHasher Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/memory/address_hasher.h ('k') | base/memory/shared_memory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/memory/address_hasher.cc
diff --git a/base/memory/address_hasher.cc b/base/memory/address_hasher.cc
new file mode 100644
index 0000000000000000000000000000000000000000..69ea83be7f3114b399947ca82bada6d131f32998
--- /dev/null
+++ b/base/memory/address_hasher.cc
@@ -0,0 +1,23 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/memory/address_hasher.h"
+
+namespace base {
+
+size_t AddressHasher::operator()(const void* address) const {
danakj 2017/02/22 15:28:01 There's no reason to make this an operator() inste
hajimehoshi 2017/02/23 07:23:50 This is just copied from heap_profiler_allocation_
+ // The multiplicative hashing scheme from [Knuth 1998]. The value of |a| has
+ // been chosen carefully based on measurements with real-word data (addresses
+ // recorded from a Chrome trace run). It is the first prime after 2^17. For
danakj 2017/02/22 15:28:01 When you say measurements of real-word (should be
hajimehoshi 2017/02/23 07:23:50 ditto.
+ // |shift|, 15 yield good results for both 2^18 and 2^19 bucket sizes.
+ // Microbenchmarks show that this simple scheme outperforms fancy hashes like
+ // Murmur3 by 20 to 40 percent.
+ const uintptr_t key = reinterpret_cast<uintptr_t>(address);
+ const uintptr_t a = 131101;
+ const uintptr_t shift = 15;
+ const uintptr_t h = (key * a) >> shift;
+ return h;
+}
+
+} // namespace base
« no previous file with comments | « base/memory/address_hasher.h ('k') | base/memory/shared_memory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698