From e18a30c22f4138cd4f9b69909f526e0087f4b561 Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Wed, 29 Jul 2026 14:17:33 -0500 Subject: [PATCH] Accelerate SHA-256 hashing on aarch64 --- Cargo.lock | 11 +++++++++++ crates/uv-bench/Cargo.toml | 1 + crates/uv-bench/benches/uv.rs | 11 +++++++++++ crates/uv-extract/Cargo.toml | 3 +++ 4 files changed, 26 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 3ffa2cfdb3d..5e11d922699 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4649,6 +4649,7 @@ dependencies = [ "cfg-if", "cpufeatures 0.2.17", "digest 0.10.7", + "sha2-asm", ] [[package]] @@ -4662,6 +4663,15 @@ dependencies = [ "digest 0.11.3", ] +[[package]] +name = "sha2-asm" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b845214d6175804686b2bd482bcffe96651bb2d1200742b712003504a2dac1ab" +dependencies = [ + "cc", +] + [[package]] name = "sharded-slab" version = "0.1.7" @@ -5972,6 +5982,7 @@ dependencies = [ "fs-err", "futures", "jiff", + "sha2 0.10.9", "tempfile", "tokio", "tokio-util", diff --git a/crates/uv-bench/Cargo.toml b/crates/uv-bench/Cargo.toml index ba8a389110b..bfd2977d8dc 100644 --- a/crates/uv-bench/Cargo.toml +++ b/crates/uv-bench/Cargo.toml @@ -65,6 +65,7 @@ flate2 = { workspace = true } fs-err = { workspace = true } futures = { workspace = true } jiff = { workspace = true } +sha2 = { workspace = true } tempfile = { workspace = true } tokio = { workspace = true } tokio-util = { workspace = true } diff --git a/crates/uv-bench/benches/uv.rs b/crates/uv-bench/benches/uv.rs index d37339178c6..5cc61d93772 100644 --- a/crates/uv-bench/benches/uv.rs +++ b/crates/uv-bench/benches/uv.rs @@ -14,6 +14,7 @@ use criterion::{BatchSize, Criterion, criterion_group, criterion_main, measureme use flate2::write::GzEncoder; use futures::executor::block_on; use futures::io::AllowStdIo; +use sha2::{Digest, Sha256}; use tokio_util::compat::{FuturesAsyncReadCompatExt, FuturesAsyncWriteCompatExt}; use uv_cache::Cache; use uv_client::{BaseClientBuilder, Connectivity, RegistryClientBuilder}; @@ -29,6 +30,15 @@ const MANY_FILES_WHEEL_FILENAME: &str = "manyfiles-0.0.0-py3-none-any.whl"; const MANY_FILES_WHEEL_FILE_COUNT: usize = 10_000; const MANY_FILES_SDIST_TOP_LEVEL: &str = "manyfiles-0.0.0"; const MANY_FILES_SDIST_FILE_COUNT: usize = 10_000; +const SHA256_BENCHMARK_SIZE: usize = 1024 * 1024; + +fn hash_sha256(c: &mut Criterion) { + let bytes = vec![0_u8; SHA256_BENCHMARK_SIZE]; + + c.bench_function("hash_sha256", |b| { + b.iter(|| black_box(Sha256::digest(black_box(&bytes)))); + }); +} fn create_many_files_wheel() -> tempfile::NamedTempFile { let archive = tempfile::NamedTempFile::new().expect("Failed to create temporary archive"); @@ -330,6 +340,7 @@ criterion_group! { name = uv; config = criterion_with_preview(); targets = + hash_sha256, unpack_sdist_many_files, unzip_wheel_many_files, prepare_wheel_many_files, diff --git a/crates/uv-extract/Cargo.toml b/crates/uv-extract/Cargo.toml index a942cffcd22..44bcaee3d5b 100644 --- a/crates/uv-extract/Cargo.toml +++ b/crates/uv-extract/Cargo.toml @@ -39,6 +39,9 @@ tokio = { workspace = true } tokio-util = { workspace = true, features = ["compat"] } tracing = { workspace = true } +[target.'cfg(all(target_arch = "aarch64", not(target_os = "windows")))'.dependencies] +sha2 = { workspace = true, features = ["asm"] } + [features] default = []