Skip to content

Commit 67ec734

Browse files
Nicoshevfacebook-github-bot
authored andcommitted
Use rapidhashNano on folly::hasher<string/range> (#9617)
Summary: X-link: facebook/folly#2448 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 9a93d0a commit 67ec734

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

third-party/folly/src/folly/Range.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939

4040
#include <folly/Portability.h>
4141
#include <folly/hash/SpookyHashV2.h>
42+
#include <folly/hash/rapidhash.h>
4243
#include <folly/lang/CString.h>
4344
#include <folly/lang/Exception.h>
4445
#include <folly/portability/Constexpr.h>
@@ -794,7 +795,7 @@ class Range {
794795
}
795796

796797
// Do NOT use this function, which was left behind for backwards
797-
// compatibility. Use SpookyHashV2 instead -- it is faster, and produces
798+
// compatibility. Use rapidhashNano instead -- it is faster, and produces
798799
// a 64-bit hash, which means dramatically fewer collisions in large maps.
799800
// (The above advice does not apply if you are targeting a 32-bit system.)
800801
//
@@ -1698,7 +1699,7 @@ struct hasher<
16981699
// may be == without being bit-identical. size_t is less than 64
16991700
// bits on some platforms.
17001701
return static_cast<size_t>(
1701-
hash::SpookyHashV2::Hash64(r.begin(), r.size() * sizeof(T), 0));
1702+
folly::hash::rapidhashNano(r.begin(), r.size() * sizeof(T)));
17021703
}
17031704
};
17041705

third-party/folly/src/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)