Skip to content

Commit

Permalink
Change SipHash2-4 -> SipHash1-3 (#780)
Browse files Browse the repository at this point in the history
This seems to significantly improves performance. Inspired by rust-lang/rust#107925
  • Loading branch information
dccsillag committed Apr 19, 2023
1 parent f8966f9 commit d0afba9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cli/src/main.rs
Expand Up @@ -17,7 +17,7 @@ use memmap2::Mmap;
use notify::{RecommendedWatcher, RecursiveMode, Watcher};
use once_cell::unsync::OnceCell;
use same_file::{is_same_file, Handle};
use siphasher::sip128::{Hasher128, SipHasher};
use siphasher::sip128::{Hasher128, SipHasher13};
use termcolor::{ColorChoice, StandardStream, WriteColor};
use typst::diag::{FileError, FileResult, SourceError, StrResult};
use typst::eval::Library;
Expand Down Expand Up @@ -535,7 +535,7 @@ impl PathHash {
fn new(path: &Path) -> FileResult<Self> {
let f = |e| FileError::from_io(e, path);
let handle = Handle::from_path(path).map_err(f)?;
let mut state = SipHasher::new();
let mut state = SipHasher13::new();
handle.hash(&mut state);
Ok(Self(state.finish128().as_u128()))
}
Expand Down
4 changes: 2 additions & 2 deletions src/eval/value.rs
Expand Up @@ -5,7 +5,7 @@ use std::hash::{Hash, Hasher};
use std::sync::Arc;

use ecow::eco_format;
use siphasher::sip128::{Hasher128, SipHasher};
use siphasher::sip128::{Hasher128, SipHasher13};

use super::{
cast_to_value, format_str, ops, Args, Array, Cast, CastInfo, Content, Dict, Func,
Expand Down Expand Up @@ -313,7 +313,7 @@ where
fn hash128(&self) -> u128 {
// Also hash the TypeId since values with different types but
// equal data should be different.
let mut state = SipHasher::new();
let mut state = SipHasher13::new();
self.type_id().hash(&mut state);
self.hash(&mut state);
state.finish128().as_u128()
Expand Down
4 changes: 2 additions & 2 deletions src/util/mod.rs
Expand Up @@ -12,7 +12,7 @@ use std::num::NonZeroUsize;
use std::path::{Component, Path, PathBuf};
use std::sync::Arc;

use siphasher::sip128::{Hasher128, SipHasher};
use siphasher::sip128::{Hasher128, SipHasher13};

/// Turn a closure into a struct implementing [`Debug`].
pub fn debug<F>(f: F) -> impl Debug
Expand All @@ -35,7 +35,7 @@ where

/// Calculate a 128-bit siphash of a value.
pub fn hash128<T: Hash + ?Sized>(value: &T) -> u128 {
let mut state = SipHasher::new();
let mut state = SipHasher13::new();
value.hash(&mut state);
state.finish128().as_u128()
}
Expand Down

0 comments on commit d0afba9

Please sign in to comment.