Skip to content

Commit 3860251

Browse files
committed
Auto merge of #110410 - saethlin:hash-u128-as-u64s, r=oli-obk
Implement StableHasher::write_u128 via write_u64 In #110367 (comment) the cachegrind diffs indicate that nearly all the regression is from this: ``` 22,892,558 ???:<rustc_data_structures::sip128::SipHasher128>::slice_write_process_buffer -9,502,262 ???:<rustc_data_structures::sip128::SipHasher128>::short_write_process_buffer::<8> ``` Which happens because the diff for that perf run swaps a `Hash::hash` of a `u64` to a `u128`. But `slice_write_process_buffer` is a `#[cold]` function, and is for handling hashes of arbitrary-length byte arrays. Using the much more optimizer-friendly `u64` path twice to hash a `u128` provides a nice perf boost in some benchmarks.
2 parents e279f90 + ad8d304 commit 3860251

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ impl Hasher for StableHasher {
107107

108108
#[inline]
109109
fn write_u128(&mut self, i: u128) {
110-
self.state.write(&i.to_le_bytes());
110+
self.write_u64(i as u64);
111+
self.write_u64((i >> 64) as u64);
111112
}
112113

113114
#[inline]

0 commit comments

Comments
 (0)