From 98e088e731e6fbd5b5035033ae61bda823ced988 Mon Sep 17 00:00:00 2001 From: dtzxporter Date: Tue, 12 Sep 2023 18:15:00 -0400 Subject: [PATCH 1/3] Migrate twox-hash -> xxhash_rust. Switch to Xxh3 for better performance. xxhash-rust is more maintained, built against `::core`, so no workaround for wasm is necessary. Switch to Xxh3 for better performance, which shows when loading/hashing image buffers. --- Cargo.toml | 2 +- core/Cargo.toml | 2 +- core/src/hasher.rs | 5 +++-- graphics/Cargo.toml | 6 +----- graphics/src/text/cache.rs | 6 +----- tiny_skia/Cargo.toml | 6 +----- 6 files changed, 8 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1a286b9bf9..f625f1adf1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,7 +150,7 @@ thiserror = "1.0" tiny-skia = "0.10" tokio = "1.0" tracing = "0.1" -twox-hash = { version = "1.0", default-features = false } +xxhash-rust = { version = "0.8.7", default-features = false, features = ["xxh3"] } unicode-segmentation = "1.0" wasm-bindgen-futures = "0.4" wasm-timer = "0.2" diff --git a/core/Cargo.toml b/core/Cargo.toml index 7acb751119..8294684726 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -14,7 +14,7 @@ keywords.workspace = true bitflags.workspace = true log.workspace = true thiserror.workspace = true -twox-hash.workspace = true +xxhash-rust.workspace = true num-traits.workspace = true palette.workspace = true diff --git a/core/src/hasher.rs b/core/src/hasher.rs index 9d8f75b38c..a13d78afcd 100644 --- a/core/src/hasher.rs +++ b/core/src/hasher.rs @@ -1,6 +1,7 @@ /// The hasher used to compare layouts. -#[derive(Debug, Default)] -pub struct Hasher(twox_hash::XxHash64); +#[allow(missing_debug_implementations)] // Doesn't really make sense to have debug on the hasher state anyways. +#[derive(Default)] +pub struct Hasher(xxhash_rust::xxh3::Xxh3); impl core::hash::Hasher for Hasher { fn write(&mut self, bytes: &[u8]) { diff --git a/graphics/Cargo.toml b/graphics/Cargo.toml index 3165810b09..a7aea35202 100644 --- a/graphics/Cargo.toml +++ b/graphics/Cargo.toml @@ -33,8 +33,8 @@ once_cell.workspace = true raw-window-handle.workspace = true rustc-hash.workspace = true thiserror.workspace = true -twox-hash.workspace = true unicode-segmentation.workspace = true +xxhash-rust.workspace = true image.workspace = true image.optional = true @@ -44,7 +44,3 @@ kamadak-exif.optional = true lyon_path.workspace = true lyon_path.optional = true - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -twox-hash.workspace = true -twox-hash.features = ["std"] diff --git a/graphics/src/text/cache.rs b/graphics/src/text/cache.rs index b3293dd469..7fb335678d 100644 --- a/graphics/src/text/cache.rs +++ b/graphics/src/text/cache.rs @@ -16,11 +16,7 @@ pub struct Cache { hasher: HashBuilder, } -#[cfg(not(target_arch = "wasm32"))] -type HashBuilder = twox_hash::RandomXxHashBuilder64; - -#[cfg(target_arch = "wasm32")] -type HashBuilder = std::hash::BuildHasherDefault; +type HashBuilder = xxhash_rust::xxh3::Xxh3Builder; impl Cache { /// Creates a new empty [`Cache`]. diff --git a/tiny_skia/Cargo.toml b/tiny_skia/Cargo.toml index 15a6928a30..df4c614332 100644 --- a/tiny_skia/Cargo.toml +++ b/tiny_skia/Cargo.toml @@ -26,11 +26,7 @@ raw-window-handle.workspace = true rustc-hash.workspace = true softbuffer.workspace = true tiny-skia.workspace = true -twox-hash.workspace = true +xxhash-rust.workspace = true resvg.workspace = true resvg.optional = true - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -twox-hash.workspace = true -twox-hash.features = ["std"] From 4b69c71d5b570ce716b9c202e9a47d5ae9ce3ae0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 11 Nov 2023 03:43:03 +0100 Subject: [PATCH 2/3] Remove patch version from `xxhash-rust` dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f625f1adf1..4bcf7c7aed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,7 +150,7 @@ thiserror = "1.0" tiny-skia = "0.10" tokio = "1.0" tracing = "0.1" -xxhash-rust = { version = "0.8.7", default-features = false, features = ["xxh3"] } +xxhash-rust = { version = "0.8", default-features = false, features = ["xxh3"] } unicode-segmentation = "1.0" wasm-bindgen-futures = "0.4" wasm-timer = "0.2" From 107e842071f1300df5e0bfcb26ee0a99024e51d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ram=C3=B3n=20Jim=C3=A9nez?= Date: Sat, 11 Nov 2023 03:43:50 +0100 Subject: [PATCH 3/3] Remove unnecessary `default-features` attribute from `xxhash-rust` dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 4bcf7c7aed..ac34a4acb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -150,7 +150,7 @@ thiserror = "1.0" tiny-skia = "0.10" tokio = "1.0" tracing = "0.1" -xxhash-rust = { version = "0.8", default-features = false, features = ["xxh3"] } +xxhash-rust = { version = "0.8", features = ["xxh3"] } unicode-segmentation = "1.0" wasm-bindgen-futures = "0.4" wasm-timer = "0.2"