Skip to main content
Bun provides high-performance hashing functions for checksums, data integrity, and hash tables. All implementations are optimized with SIMD instructions where available.

Quick Start

Non-Cryptographic Hashes

Fast hashes for hash tables, checksums, and data structures.

Wyhash

Default hash function, extremely fast:
Characteristics:
  • Speed: ~25 GB/s
  • Output: 64-bit
  • Collision resistance: Excellent
  • Use for: Hash tables, general purpose

CityHash

Google’s CityHash family:
Characteristics:
  • Speed: ~20 GB/s
  • Output: 32-bit or 64-bit
  • Use for: Hash tables, databases

xxHash

Extremely fast hash with excellent distribution:
Characteristics:
  • Speed: xxHash3 ~30 GB/s, others ~15 GB/s
  • Output: 32-bit or 64-bit
  • Collision resistance: Excellent
  • Use for: Checksums, hash tables, caching

Murmur Hash

Popular hash used in many databases:
Characteristics:
  • Speed: ~5 GB/s
  • Output: 32-bit or 64-bit
  • Use for: Hash tables, Bloom filters

CRC32

Cyclic redundancy check, hardware accelerated:
Characteristics:
  • Speed: ~10 GB/s (hardware accelerated)
  • Output: 32-bit
  • Use for: Data integrity, checksums

Adler-32

Simpler checksum algorithm:
Characteristics:
  • Speed: ~15 GB/s
  • Output: 32-bit
  • Use for: Checksums (faster but less reliable than CRC32)

Input Types

All hash functions accept multiple input types:

Strings

TypedArrays

ArrayBuffer

Blob

Cryptographic Hashes

For security-sensitive applications, use cryptographic hash functions:

SHA-256

SHA-512

Other SHA Variants

MD4 and MD5

⚠️ Warning: MD4 and MD5 are cryptographically broken. Only use for legacy compatibility.

Performance Comparison

Throughput Benchmark

Common Use Cases

Hash Table Keys

File Integrity

Content Addressing

Deduplication

Cache Keys

Password Hashing

⚠️ Warning: Use proper password hashing like bcrypt or Argon2. Never use fast hashes for passwords.

Seeds and Determinism

All hash functions support seeds for deterministic results:

Reproducible Builds

Hash Quality

Collision Resistance

Test hash distribution:

Avalanche Effect

Small input changes should produce large hash changes:

Best Practices

  1. Choose the right hash for your use case
    • Hash tables: wyhash, xxHash3
    • Checksums: crc32, xxHash64
    • Security: SHA256, SHA512
    • Legacy: MD5 (only if required)
  2. Use seeds for reproducibility
  3. Consider hash size
  4. Benchmark for your data

Platform Differences

Hardware Acceleration

  • x86_64: CRC32, SHA use CPU instructions
  • ARM64: CRC32, SHA use NEON instructions
  • Other: Software fallback

Endianness

Hashes are consistent across platforms:

API Reference

hash()

Default fast hash function (Wyhash):

hash.wyhash()

hash.xxHash3()

hash.crc32()

See FFI documentation for low-level hash implementations.