From 90ea99cbefcce1e65545f4c145c743fa02f3a825 Mon Sep 17 00:00:00 2001 From: Don MacAskill Date: Tue, 23 Dec 2025 14:41:42 -0800 Subject: [PATCH 1/3] Use crc-fast for increased performance The crc-fast crate is a drop-in replacement that delivers considerably higher performance (>100GiB/s on latest x86_64 Intel, >50GiB/s on latest x86_64 AMD and aarch64 AWS Graviton, including similar gains for much older x86, x86_64, and aarch64 processors). It has a fast, safe, table-based software fallback for non-accelerated systems. --- Cargo.toml | 2 +- src/crc.rs | 30 +++++++++++++++++------------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d41209c5..7e6976fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,8 @@ cloudflare-zlib-sys = { version = "0.3.6", optional = true } ## This implementation uses only safe Rust code and doesn't require a C compiler. ## It provides good performance for most use cases while being completely portable. miniz_oxide = { version = "0.8.5", optional = true, default-features = false, features = ["with-alloc", "simd"] } -crc32fast = "1.2.0" document-features = { version = "0.2", optional = true } +crc-fast = "1.9" [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] miniz_oxide = { version = "0.8.5", default-features = false, features = ["with-alloc", "simd"] } diff --git a/src/crc.rs b/src/crc.rs index 991cc957..ab63fd94 100644 --- a/src/crc.rs +++ b/src/crc.rs @@ -3,15 +3,14 @@ use std::io; use std::io::prelude::*; -use crc32fast::Hasher; +use crc_fast::{CrcAlgorithm, Digest}; /// The CRC calculated by a [`CrcReader`]. /// /// [`CrcReader`]: struct.CrcReader.html -#[derive(Debug, Default)] +#[derive(Debug, Clone)] pub struct Crc { - amt: u32, - hasher: Hasher, + digest: Digest, } /// A wrapper around a [`Read`] that calculates the CRC. @@ -23,39 +22,44 @@ pub struct CrcReader { crc: Crc, } +impl Default for Crc { + fn default() -> Self { + Self::new() + } +} + impl Crc { /// Create a new CRC. pub fn new() -> Self { - Self::default() + Crc { + digest: Digest::new(CrcAlgorithm::Crc32IsoHdlc), + } } /// Returns the current crc32 checksum. pub fn sum(&self) -> u32 { - self.hasher.clone().finalize() + self.digest.finalize() as u32 } /// The number of bytes that have been used to calculate the CRC. /// This value is only accurate if the amount is lower than 232. pub fn amount(&self) -> u32 { - self.amt + self.digest.get_amount() as u32 } /// Update the CRC with the bytes in `data`. pub fn update(&mut self, data: &[u8]) { - self.amt = self.amt.wrapping_add(data.len() as u32); - self.hasher.update(data); + self.digest.update(data); } /// Reset the CRC. pub fn reset(&mut self) { - self.amt = 0; - self.hasher.reset(); + self.digest.reset(); } /// Combine the CRC with the CRC for the subsequent block of bytes. pub fn combine(&mut self, additional_crc: &Crc) { - self.amt = self.amt.wrapping_add(additional_crc.amt); - self.hasher.combine(&additional_crc.hasher); + self.digest.combine(&additional_crc.digest); } } From c9a93552019192b3c0abd09301c8fec29a14f638 Mon Sep 17 00:00:00 2001 From: Don MacAskill Date: Tue, 23 Dec 2025 15:07:54 -0800 Subject: [PATCH 2/3] Update rust-version to 1.89.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.89.0 is still within this project’s MSRV (stable is currently 1.92.0). It’s the release that stabilized the AVX512 intrinsics, which help supply many (but not all) of these impressive performance improvements on x86_64 CPUs. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7e6976fe..ecd6851f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,7 @@ version = "1.1.7" edition = "2018" license = "MIT OR Apache-2.0" readme = "README.md" -rust-version = "1.67.0" +rust-version = "1.89.0" keywords = ["gzip", "deflate", "zlib", "zlib-ng", "encoding"] categories = ["compression", "api-bindings"] repository = "https://github.com/rust-lang/flate2-rs" From 1f009f1090f8ef307378d4163d2aec0059a24cf5 Mon Sep 17 00:00:00 2001 From: Don MacAskill Date: Wed, 31 Dec 2025 11:45:30 -0800 Subject: [PATCH 3/3] Use crc-fast 1.10.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduces dependency tree (removes ‘crc’, ‘crc-catalog’, and’ rustversion’). --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index ecd6851f..16ec116d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ cloudflare-zlib-sys = { version = "0.3.6", optional = true } ## It provides good performance for most use cases while being completely portable. miniz_oxide = { version = "0.8.5", optional = true, default-features = false, features = ["with-alloc", "simd"] } document-features = { version = "0.2", optional = true } -crc-fast = "1.9" +crc-fast = "1.10.0" [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] miniz_oxide = { version = "0.8.5", default-features = false, features = ["with-alloc", "simd"] }