Skip to content

Commit b91daf4

Browse files
Nicoshevfacebook-github-bot
authored andcommitted
Use rapidhashNano on folly::hasher<string/range> (#2448)
Summary: Replacing SpookyHashV2 with rapidhashNano folly::hasher::operator() accounts for almost 3M$ in $cpu_t1_equiv_per_year_q2_2025 https://fburl.com/strobelight/izute4k3 Given that integral hashing is the identity function, most of the registered cycles should come from strings/byteRanges See D66326393 and D75697257 for a detailed discussion around benchmarks and canaries Differential Revision: D76052916
1 parent 0ecb994 commit b91daf4

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

folly/BUCK

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,14 +846,14 @@ non_fbcode_target(
846846
exported_deps = [
847847
"//third-party/fmt:fmt",
848848
"//xplat/folly:cpu_id",
849-
"//xplat/folly:hash_spooky_hash_v2",
850849
"//xplat/folly:likely",
851850
"//xplat/folly:portability",
852851
"//xplat/folly:portability_constexpr",
853852
"//xplat/folly:traits",
854853
"//xplat/folly/detail:range_common",
855854
"//xplat/folly/detail:range_simd",
856855
"//xplat/folly/detail:range_sse42",
856+
"//xplat/folly/hash:rapidhash",
857857
"//xplat/folly/lang:c_string",
858858
"//xplat/folly/lang:exception",
859859
],
@@ -7436,7 +7436,7 @@ fbcode_target(
74367436
":traits",
74377437
"//folly/detail:range_common",
74387438
"//folly/detail:range_simd",
7439-
"//folly/hash:spooky_hash_v2",
7439+
"//folly/hash:rapidhash",
74407440
"//folly/lang:c_string",
74417441
"//folly/lang:exception",
74427442
"//folly/portability:constexpr",

folly/Range.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#pragma once
3939

4040
#include <folly/Portability.h>
41-
#include <folly/hash/SpookyHashV2.h>
41+
#include <folly/hash/rapidhash.h>
4242
#include <folly/lang/CString.h>
4343
#include <folly/lang/Exception.h>
4444
#include <folly/portability/Constexpr.h>
@@ -794,7 +794,7 @@ class Range {
794794
}
795795

796796
// Do NOT use this function, which was left behind for backwards
797-
// compatibility. Use SpookyHashV2 instead -- it is faster, and produces
797+
// compatibility. Use rapidhashNano instead -- it is faster, and produces
798798
// a 64-bit hash, which means dramatically fewer collisions in large maps.
799799
// (The above advice does not apply if you are targeting a 32-bit system.)
800800
//
@@ -1698,7 +1698,7 @@ struct hasher<
16981698
// may be == without being bit-identical. size_t is less than 64
16991699
// bits on some platforms.
17001700
return static_cast<size_t>(
1701-
hash::SpookyHashV2::Hash64(r.begin(), r.size() * sizeof(T), 0));
1701+
folly::hash::rapidhashNano(r.begin(), r.size() * sizeof(T)));
17021702
}
17031703
};
17041704

folly/hash/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ fbcode_target(
4747
headers = ["Hash.h"],
4848
exported_deps = [
4949
":murmur_hash",
50+
":rapidhash",
5051
":spooky_hash_v1",
5152
":spooky_hash_v2",
5253
"//folly:c_portability",

folly/hash/Hash.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <folly/hash/MurmurHash.h>
4747
#include <folly/hash/SpookyHashV1.h>
4848
#include <folly/hash/SpookyHashV2.h>
49+
#include <folly/hash/rapidhash.h>
4950
#include <folly/lang/Bits.h>
5051

5152
namespace folly {
@@ -999,8 +1000,7 @@ struct hasher<std::string> {
9991000
using folly_is_avalanching = std::true_type;
10001001

10011002
size_t operator()(const std::string& key) const {
1002-
return static_cast<size_t>(
1003-
hash::SpookyHashV2::Hash64(key.data(), key.size(), 0));
1003+
return static_cast<size_t>(hash::rapidhashNano(key.data(), key.size()));
10041004
}
10051005
};
10061006
template <typename K>
@@ -1011,8 +1011,7 @@ struct hasher<std::string_view> {
10111011
using folly_is_avalanching = std::true_type;
10121012

10131013
size_t operator()(const std::string_view& key) const {
1014-
return static_cast<size_t>(
1015-
hash::SpookyHashV2::Hash64(key.data(), key.size(), 0));
1014+
return static_cast<size_t>(hash::rapidhashNano(key.data(), key.size()));
10161015
}
10171016
};
10181017
template <typename K>

0 commit comments

Comments
 (0)