Skip to content

Commit ddeb5e5

Browse files
Nicoshevfacebook-github-bot
authored andcommitted
Use rapidhashNano on folly::hasher<string/range>
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 0044ae0 commit ddeb5e5

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

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

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)