Chapter 25Down the Rabbit Hole: The Hash Table That Checks 16 Slots at Once
Three very different language communities ended up with the same hash map. Abseil introduced the design in 2017. Rust's HashMap switched in 1.36 (July 2019) via hashbrown. Go 1.24 rebuilt its built-in map on it in February 2025. That usually means something is genuinely better.
The idea is small: keep one extra byte per slot and use it to check sixteen slots with one instruction. The fast path is easy. The delete path is where the cleverness went.
What was wrong with the old maps#
std::unordered_mapchains through heap-allocated nodes, so a lookup follows a pointer: typically a cache miss, around 100 ns against about 1 ns in L1. Its pointer-stability promise rules out a flat layout.- Linear probing is cache-friendly, but every occupied slot walked past costs a full key comparison, and runs clump as the table fills. Tables resize early, around half to 70% full.
The brief writes itself: compare as little as possible per slot, stay in one cache line per probe step, keep the load factor high.
A strip of sticky notes above every row#
Picture a mailroom with pigeonholes in rows of 16. Above each row is a strip with one sticky note per hole holding a short fingerprint of the name. The clerk reads the strip, opens only the holes that might match, and if the strip shows a blank, the parcel was never pushed to another row, so "not here" comes back fast.
ctrl bytes (one SIMD load) ┌────┬────┬────┬────┬────┬────┬────┬────┬─────┬────┐ │ 3A │ 11 │ 7F │ 3A │ 80 │ 05 │ FE │ 62 │ ... │ 80 │ W = 16 on SSE2 └─┬──┴─┬──┴─┬──┴─┬──┴─┬──┴─┬──┴─┬──┴─┬──┴─────┴─┬──┘ (8 on NEON, fallback) │ │ │ │ │ │ │ │ │ ┌─▼──┬─▼──┬─▼──┬─▼──┬─▼──┬─▼──┬─▼──┬─▼──┬─────┬──▼─┐ │ k,v│ k,v│ k,v│ k,v│ │ k,v│ │ k,v│ ... │ │ slots └────┴────┴────┴────┴────┴────┴────┴────┴─────┴────┘ byte < 0x80: full, holds h2 (7 bits) 0x80 empty 0xFE deleted (values schematic; the real encodings differ)
The top bit does quiet work: "is it full?" is a non-negative test, "empty or deleted?" is a sign-bit test, "empty?" is one equality compare. That's why the tag is 7 bits, not 8.
The lookup#
W is the group width. The hash splits in two: h1 picks where to start, h2 is the 7-bit tag.
Pseudocode and the probe sequence
probe = ProbeSeq(h1(hash) & capacity_mask)
loop:
g = Group(ctrl + probe.offset) // W control bytes
for i in g.Match(h2(hash)): // _mm_cmpeq_epi8 + _mm_movemask_epi8, then bit-scan
if key_eq(slots[(probe.offset + i) & mask], key): return slot
if g.MaskEmpty(): return NOT_FOUND // an empty slot ends the search
probe.next() // offset += index; index += W; offset &= maskHops aren't to the neighbouring group. The step grows by one group each time, so offsets go 0, +1, +3, +6: triangular numbers, which with a power-of-two group count visit every group exactly once. Linear +1 steps would let full groups clump and stretch every probe through them.
Fingerprints lie, and that's fine#
A wrong occupied slot matches its 7-bit tag with probability 1/128. A group with 14 of 16 full wastes about 0.11 key comparisons per visit. The misconception I came in with, that a short fingerprint is a correctness risk, is wrong: a tag match only nominates a slot, and the full key is always compared.
Why 7/8 full is affordable#
Abseil lets a table fill to 7/8 before growing. A miss walks until it finds a group with an empty slot; if a fraction p of groups are full, expected groups probed is 1 / (1 - p).
The naive guess is slots full independently with probability α, so a group is full with probability α^16: about 0.118 at α = 7/8. That's badly wrong. I wrote a small simulator (aligned groups, splitmix64, 16K to 32K slots, 20,000 lookups per configuration, one seed). It models the design; it isn't a benchmark of Abseil, hashbrown or Go. At 7/8 with 16-wide groups it measured 47.6% of groups with no empty slot.
Keys don't land evenly. Group occupancy is roughly Poisson with mean αW, giving a 0.33 chance of 16 or more at 7/8, and overflow spills into neighbours, pushing it higher.
| load | W | naive guess | Poisson | measured full | groups per miss |
|---|---|---|---|---|---|
| 0.75 | 16 | 0.010 | 0.156 | 0.189 | 1.25 |
| 0.875 | 16 | 0.118 | 0.331 | 0.476 | 2.09 |
| 0.875 | 8 | 0.344 | 0.401 | 0.603 | 2.93 |
| 0.95 | 16 | 0.440 | n/a | n/a | 4.80 |
Nearly half the groups are full, yet a miss costs about two group probes and a hit about 1.1. Each step is one cheap compare, so you can afford a couple and save memory. At 0.95, misses hit almost five groups. Go uses groups of 8, which is why its simulated cost is 2.93 at 7/8: per Go's source comments, an 8-slot group holds one empty on average where Abseil's 16 hold two.
The hard part: deleting things#
You can't just mark an erased slot empty. A probe stops at the first empty. If key K overflowed from a full home group, erasing from that group and writing "empty" makes find for K stop early and report it absent. That's a correctness bug.
home group [ A B C D ] full next group [ K . . . ] K landed here lookup K: probe home, no empty, hop, find K
K was inserted when its home group was full, so it overflowed.
Tombstones cost too. Abseil's growth_left budget isn't refunded for a tombstone, so with n live entries and d tombstones the table rehashes when
n + d >= floor(7/8 * capacity)even if n is small. Churn quietly eats the table.
Abseil's trick: write "empty" anyway when the slot "was never full", meaning no probe could have passed through it: no window containing it was ever completely full, so no key overflowed past it. I'll be honest: the exact window arithmetic in raw_hash_set.cc is fiddly and I didn't reproduce it faithfully. The behaviour is certain; the precise test I wouldn't quote from memory.
What I could do is break it on purpose. In the simulator at 80% load with 60,000 delete-plus-insert rounds, always writing tombstones caused 19 rehashes; the never-full rule caused 7. Make the rule lie, and present keys start reporting absent. The rule wasn't free: the table lived nearer its ceiling, and average miss cost went from 1.67 to 2.04 groups. Single seed, simplified erase test, so it's a shape, not a number.
Where else it breaks#
- Resize spikes. Abseil and hashbrown rehash everything at once: one insert costs O(n). Go 1.24 uses a directory of tables capped at 1024 slots, splitting only the full one. That's extendible hashing in disguise, bounding the spike for a directory lookup per access.
- Hash flooding. Predictable hashes let attackers steer keys into the same groups. Crosby and Wallach showed it in 2003; a 2011 talk took down PHP, ASP.NET, Ruby, Java and Python; Aumasson, Bernstein and Boßlet (2012) showed random seeds on fast hashes weren't enough, which gave us SipHash. Rust's std defaults to SipHash 1-3. The standalone hashbrown crate defaults to foldhash, which is faster and explicitly doesn't resist an interactive attacker. Same table, different threat model.
- Not always faster. Ruby's Swiss-style
st_tableexperiment (#22011) improved microbenchmarks but showed +1.77% geomean interpreter time on ruby-bench, up to +12.5% on single benchmarks and +20% memory on one, with a possible hash bug muddying it. Go #70700 noted the swiss benchmarks used predictable key order and no cold maps; follow-ups made small-map lookups about 1.7x faster for unpredictable keys. - Pointers move. Values live inline, so rehash invalidates references. Iteration order isn't stable; Go randomises it on purpose.
What's still open#
On the CPU the design looks settled; active work has moved to GPUs and concurrent tables.
The delete keeps nagging me. Never-full avoids most tombstones but not all, and probabilistically. DLHT (HPDC 2024) gives up open addressing, chaining within cache lines so a deleted slot is reusable immediately, and reports over 1.6 billion requests per second, but changes the lookup shape. Nobody has shown a tombstone-free delete for SIMD open addressing as fast as writing a tombstone.
The theory gap: the simple α^W model is off by about 4x at 7/8 load. A 2026 preprint by Nicaud and Rotondo analyses SIMD open addressing with Wormald's differential-equation method, but its experiments simulate its own model rather than Abseil, hashbrown or Go. The most widely deployed hash table design is, as far as I can tell, running on engineering intuition that happens to be very good.
Sources#
- Abseil Swiss tables design notes
- Abseil source: raw_hash_set.h, raw_hash_set.cc
- Kulukundis, "Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step", CppCon 2017
- hashbrown, std HashMap docs, foldhash
- Go 1.24 release notes, Go Swiss map blog post, internal/runtime/maps, golang/go #70700
- Ruby Feature #22011
- Crosby and Wallach, Denial of Service via Algorithmic Complexity Attacks (USENIX Security 2003)
- Aumasson, Bernstein, Boßlet, Hash-flooding DoS reloaded (2012)
- DLHT (HPDC 2024) and WarpSpeed (ALENEX 2026)
- Nicaud and Rotondo, A Fine-Grained Analysis of SIMD-Based Hash Table Implementations (preprint, 2026)