gxhash

A blazingly fast, SIMD-accelerated non-cryptographic hashing algorithm for Rust with zero dependencies.

Library
Cargo
v3.5.0
1,022stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
34/100Needs Attention
Development Activity4
Maintenance0
Community44
Maturity48
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture82
Code Quality78
Innovation88
Learning Curve75

GxHash is a non-cryptographic hashing algorithm for Rust built around heavy use of SIMD intrinsics (AES-NI on x86, ARM AES+NEON on aarch64), high instruction-level parallelism, and a deliberately small bytecode footprint that inlines and caches well. It hashes arbitrary byte streams to 32-, 64-, or 128-bit outputs and ships a Hasher/BuildHasher implementation (GxHasher, GxBuildHasher) with drop-in HashMap/HashSet type aliases, making it usable as a fast general replacement for Rust’s default SipHash-based hasher.

Despite the aggressive unsafe optimizations used to hit its throughput numbers, GxHash uses several rounds of hardware-accelerated AES block cipher for bit mixing and passes the full SMHasher test suite, the standard quality benchmark for non-cryptographic hashers, giving it low collision rates and strong avalanche behavior. It has zero cargo dependencies in its core hashing path, supports no_std environments, and is seeded with randomization by default (or deterministically via a feature flag) to resist hash-flooding DOS attacks against structures like HashMap.

What You Get

  • Direct hash functions - gxhash32, gxhash64, and gxhash128 for hashing an arbitrary byte slice with a seed, no setup required.
  • Hasher trait implementation - GxHasher implements std::hash::Hasher so it plugs into any API that accepts a custom hasher.
  • DOS-resistant BuildHasher - GxBuildHasher randomizes its seed by default (backed by RandomState) so repeated HashMap::default() calls aren’t predictable to an attacker.
  • Ready-made collection aliases - gxhash::HashMap and gxhash::HashSet type aliases plus HashMapExt/HashSetExt convenience traits for new()/with_capacity().
  • no_std support - the core hashing functions build without the standard library; the Hasher/collection types are gated behind the default-on std feature.
  • Optional hybrid mode - a hybrid feature flag (nightly-only) enables wider VAES+AVX2 registers for higher throughput on large inputs while preserving identical hash output.

Common Use Cases

  • Fast in-memory HashMap/HashSet keys - swapping Rust’s default SipHash for gxhash::HashMap in hot paths where keys are trusted or DOS resistance from randomized seeding is sufficient.
  • Checksumming and deduplication - hashing byte buffers (files, network payloads, cache entries) to detect duplicates or changes without cryptographic guarantees.
  • Content-addressed caching - using gxhash128 output as a cache key or bucket identifier where speed matters more than cryptographic collision resistance.
  • High-throughput data pipelines - hashing large volumes of data (e.g. in databases, search indexes, or bloom filters) where hash computation is a measurable bottleneck.

Under The Hood

Architecture The crate is organized around a tiny public surface (src/lib.rs) that re-exports two modules: gxhash (the core algorithm in src/gxhash/mod.rs, no_std-compatible) and hasher (the std-gated Hasher/BuildHasher/collection-alias layer in src/hasher.rs). The actual SIMD primitives live behind a platform module with parallel x86.rs and arm.rs implementations selected at compile time via cfg(target_arch), each defining the same primitive set (create_empty, create_seed, load_unaligned, aes_encrypt, get_partial_safe/get_partial_unsafe) so the algorithm code in mod.rs is architecture-agnostic. compress_all branches by input length (empty, single-vector, multi-vector with unrolled 8-block processing in compress_many) to keep small inputs cheap while giving large inputs a high-ILP loop; a companion ffi/ crate exposes a C ABI over the same core. A build.rs plus compile_error! guards in the platform modules hard-fail the build on CPUs lacking AES-NI/SSE2 or AES/NEON rather than falling back to a slower path.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search