Keyboard shortcuts

Press ← or β†’ to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

PulseMap

A CPU cache-line hash table with zero-cost eviction.

πŸ’‘ Use PulseMap anywhere you’d use HashMap but can’t afford unbounded memory growth.


What is PulseMap?

PulseMap is a bounded, concurrent hash table where every bucket fits in exactly one 64-byte CPU cache line. Unlike HashMap which grows forever until you run out of memory, PulseMap has a fixed capacity and automatically evicts the least-useful entries when full.

Key insight: By packing metadata (state, H2 fingerprint, frequency counter, recency bits) into the same cache line as the data slots, eviction decisions cost zero additional cache misses.

Why PulseMap?

ProblemHashMapRedisPulseMap
Memory growth❌ Unbounded β†’ OOMβœ… Boundedβœ… Bounded
Lookup latency~10ns~100ΞΌs (network)~5ns
Eviction❌ Noneβœ… LRUβœ… LFU+LRU hybrid
Thread safety❌ Mutex<HashMap>βœ… Single-threadedβœ… Per-bucket locks
GC pausesN/AN/AZero
Cache efficiency❌ RandomN/Aβœ… 1 cache line/bucket

Quick Example

#![allow(unused)]
fn main() {
use pulse_map::ConcurrentPulseMap;
use std::sync::Arc;
use std::thread;

// Create a thread-safe map with auto-resize
let map = Arc::new(ConcurrentPulseMap::<String, u64>::with_auto_resize(256));

// Concurrent writes from 4 threads
let handles: Vec<_> = (0..4).map(|t| {
    let m = map.clone();
    thread::spawn(move || {
        for i in 0..1000 {
            m.insert(format!("key_{}", t * 1000 + i), i as u64);
        }
    })
}).collect();

for h in handles { h.join().unwrap(); }

// Read back
assert!(map.get(&"key_0".to_string()).is_some());
println!("Entries: {}, Evictions: {}", map.len(), map.eviction_count());
}

Features

  • πŸ—οΈ Cache-Line Architecture β€” 64-byte buckets with 4 slots each
  • ⚑ Zero-Cost Eviction β€” LFU+LRU metadata embedded in bucket
  • πŸ”’ Thread-Safe β€” Per-bucket spinlocks, &self API
  • πŸ—οΈ 16-Shard Concurrency β€” ShardedPulseMap: 2.4–3.1x faster than global lock
  • ⏱️ Per-Entry TTL β€” Individual expiry per key, or global default
  • πŸ“ Bounded Memory β€” Fixed capacity, no unbounded growth
  • πŸ”„ Auto-Resize β€” Optional dynamic growth at 75% load
  • 🌐 C FFI Bindings β€” Use from C, or build your own language bridge
  • πŸ”§ no_std Compatible β€” Core data structures work without allocator

Supported Platforms

PlatformStatus
Linux x86_64βœ…
macOS x86_64 / ARM64βœ…
Windows x86_64βœ…
MSRV: Rust 1.70.0βœ…

License

Dual licensed under MIT or Apache-2.0.

Copyright (c) 2026 Deendayal Kumawat.