Skip to content

Commit

Permalink
Auto merge of #45319 - michaelwoerister:use-128bit-siphash, r=nikomat…
Browse files Browse the repository at this point in the history
…sakis

incr.comp.: Use 128bit SipHash for fingerprinting

This PR switches incr. comp. result fingerprinting from 128 bit BLAKE2 to 128 bit SipHash. When we started using BLAKE2 for fingerprinting, the 128 bit version of SipHash was still experimental. Now that it isn't anymore we should be able to get a nice performance boost without significantly increasing collision probability.

~~I'm going to start a try-build for this, so we can gauge the performance impact before merging (hence the `WIP` in the title).~~

EDIT: Performance improvements look as expected. Tests seem to be passing.

Fixes #41215.
  • Loading branch information
bors committed Oct 20, 2017
2 parents c0e0a38 + 27b6c91 commit c0956ff
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 83 deletions.
1 change: 1 addition & 0 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct Hasher<S: Sip> {
}

#[derive(Debug, Clone, Copy)]
#[repr(C)]
struct State {
// v0, v2 and v1, v3 show up in pairs in the algorithm,
// and simd implementations of SipHash will use vectors
Expand Down
15 changes: 3 additions & 12 deletions src/librustc/ich/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
// except according to those terms.

use rustc_data_structures::stable_hasher;
use std::mem;
use std::slice;

#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, RustcEncodable, RustcDecodable)]
pub struct Fingerprint(u64, u64);
Expand Down Expand Up @@ -54,16 +52,9 @@ impl ::std::fmt::Display for Fingerprint {
}

impl stable_hasher::StableHasherResult for Fingerprint {
fn finish(mut hasher: stable_hasher::StableHasher<Self>) -> Self {
let hash_bytes: &[u8] = hasher.finalize();

assert!(hash_bytes.len() >= mem::size_of::<u64>() * 2);
let hash_bytes: &[u64] = unsafe {
slice::from_raw_parts(hash_bytes.as_ptr() as *const u64, 2)
};

// The bytes returned bytes the Blake2B hasher are always little-endian.
Fingerprint(u64::from_le(hash_bytes[0]), u64::from_le(hash_bytes[1]))
fn finish(hasher: stable_hasher::StableHasher<Self>) -> Self {
let (_0, _1) = hasher.finalize();
Fingerprint(_0, _1)
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#![feature(fn_traits)]
#![feature(unsize)]
#![feature(i128_type)]
#![feature(i128)]
#![feature(conservative_impl_trait)]
#![feature(specialization)]

Expand All @@ -54,6 +55,7 @@ pub mod graph;
pub mod indexed_set;
pub mod indexed_vec;
pub mod obligation_forest;
pub mod sip128;
pub mod snapshot_map;
pub mod snapshot_vec;
pub mod stable_hasher;
Expand Down
Loading

0 comments on commit c0956ff

Please sign in to comment.