Skip to content

Commit

Permalink
Change SipHash2-4 -> SipHash1-3
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 13, 2023
1 parent 0105eb7 commit 79bfbcd
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 79bfbcd

Please sign in to comment.