Skip to content

Commit f28774a

Browse files
goldvitalycopybara-github
authored andcommitted
Avoid mixing after Hash64 calls for long strings by passing state instead of Seed to low level hash.
``` name old INSTRUCTIONS/op new INSTRUCTIONS/op delta BM_latency_AbslHash_Int32 9.00 ± 0% 9.00 ± 0% ~ (all samples are equal) BM_latency_AbslHash_Int64 9.00 ± 0% 9.00 ± 0% ~ (all samples are equal) BM_latency_AbslHash_String3 32.0 ± 0% 32.0 ± 0% ~ (all samples are equal) BM_latency_AbslHash_String5 30.9 ± 3% 31.0 ± 4% ~ (p=0.328 n=54+56) BM_latency_AbslHash_String9 29.0 ± 4% 28.9 ± 3% ~ (p=0.413 n=55+53) BM_latency_AbslHash_String17 27.0 ± 3% 27.4 ± 2% +1.74% (p=0.000 n=53+50) BM_latency_AbslHash_String33 32.5 ± 5% 32.9 ± 6% +1.23% (p=0.002 n=55+52) BM_latency_AbslHash_String65 63.6 ±14% 55.9 ±11% -12.02% (p=0.000 n=56+51) BM_latency_AbslHash_String257 134 ±10% 122 ±10% -8.91% (p=0.000 n=52+49) name old CYCLES/op new CYCLES/op delta BM_latency_AbslHash_Int32 16.1 ± 2% 16.0 ± 4% ~ (p=0.108 n=51+56) BM_latency_AbslHash_Int64 16.5 ± 4% 16.4 ± 5% ~ (p=0.074 n=54+54) BM_latency_AbslHash_String3 22.7 ± 1% 22.6 ± 0% -0.50% (p=0.000 n=54+53) BM_latency_AbslHash_String5 22.9 ± 8% 22.5 ± 7% -2.08% (p=0.011 n=56+55) BM_latency_AbslHash_String9 23.1 ±15% 22.1 ± 7% -4.62% (p=0.000 n=57+52) BM_latency_AbslHash_String17 21.7 ± 8% 21.4 ± 3% -1.54% (p=0.001 n=55+55) BM_latency_AbslHash_String33 23.5 ± 4% 23.6 ± 5% ~ (p=0.206 n=53+53) BM_latency_AbslHash_String65 32.5 ± 8% 28.8 ± 7% -11.29% (p=0.000 n=57+53) BM_latency_AbslHash_String257 51.7 ± 9% 46.5 ± 7% -9.93% (p=0.000 n=54+50) ``` PiperOrigin-RevId: 759037628 Change-Id: I22e8c8e777901906015a29377b0ebd9c33310cf0
1 parent 2fe3c4b commit f28774a

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

absl/hash/internal/hash.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ uint64_t MixingHashState::CombineLargeContiguousImpl32(
4444
uint64_t MixingHashState::CombineLargeContiguousImpl64(
4545
uint64_t state, const unsigned char* first, size_t len) {
4646
while (len >= PiecewiseChunkSize()) {
47-
state = Mix(state ^ Hash64(first, PiecewiseChunkSize()), kMul);
47+
state = Hash64(first, PiecewiseChunkSize(), state);
4848
len -= PiecewiseChunkSize();
4949
first += PiecewiseChunkSize();
5050
}

absl/hash/internal/hash.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,12 +1324,13 @@ class ABSL_DLL MixingHashState : public HashStateBase<MixingHashState> {
13241324
}
13251325

13261326
ABSL_ATTRIBUTE_ALWAYS_INLINE static uint64_t Hash64(const unsigned char* data,
1327-
size_t len) {
1327+
size_t len,
1328+
uint64_t state) {
13281329
#ifdef ABSL_HAVE_INTRINSIC_INT128
1329-
return LowLevelHashLenGt32(data, len, Seed());
1330+
return LowLevelHashLenGt32(data, len, state);
13301331
#else
13311332
return hash_internal::CityHash64WithSeed(
1332-
reinterpret_cast<const char*>(data), len, Seed());
1333+
reinterpret_cast<const char*>(data), len, state);
13331334
#endif
13341335
}
13351336

@@ -1399,7 +1400,7 @@ inline uint64_t MixingHashState::CombineContiguousImpl(
13991400
return CombineContiguousImpl17to32(state, first, len);
14001401
}
14011402
if (ABSL_PREDICT_TRUE(len <= PiecewiseChunkSize())) {
1402-
return Mix(state ^ Hash64(first, len), kMul);
1403+
return Hash64(first, len, state);
14031404
}
14041405
return CombineLargeContiguousImpl64(state, first, len);
14051406
}

0 commit comments

Comments
 (0)