CodeName OneShai Almog8 min readadvanced
Faster Maps: Chasing Swiss Speed
Summary
ParparVM’s HashMap suffered catastrophic miss latency due to linear probing on dense integer keys. By adopting CPython‑style perturbed probing (Swiss‑table style) and extending tagged immediate values to more primitives, miss latency dropped from 32 s to ~45 ms, allocation pressure fell dramatically, and overall performance stayed roughly flat despite a modest hit‑time slowdown.
- Linear probing on dense key ranges can cause thousands of probes for a missing key; probe sequence matters as much as hash quality.
- Adopting CPython’s perturbed probing (Swiss‑table style) reduces miss probes to ~1‑2 while keeping first‑slot lookup fast.
- Scrambling hashes aggressively fixes miss latency but harms dense‑key scans; the chosen hybrid keeps the first slot unchanged and only perturbs thereafter.
- Extending tagged immediate representations to Short, Char, Float, Long, and Double eliminates most wrapper allocations for numeric values, cutting boxed allocations per map from 24 → 5 in a JSON‑like workload.
HashMap lookups dominate many Java workloads, especially in parsers and caches. A pathological miss can dominate latency and GC pressure. The article shows a concrete, measured redesign that eliminates that pathology and reduces allocation churn, offering a practical template for other VM or runtim…
8/10

