Concurrent Robin Hood Hashing

Robert Kelly, Barak A. Pearlmutter, Phil Maguire · DOI

Abstract

In this paper we examine the issues involved in adding concurrency to the Robin Hood hash table algorithm. We present a non-blocking obstruction-free K-CAS Robin Hood algorithm which requires only a single word compare-and-swap primitive, thus making it highly portable. The implementation maintains the attractive properties of the original Robin Hood structure, such as a low expected probe length, capability to operate effectively under a high load factor and good cache locality, all of which are essential for high performance on modern computer architectures. We compare our data-structures to various other lock-free and concurrent algorithms, as well as a simple hardware transactional variant, and show that our implementation performs better across a number of contexts.

The Challenge of Concurrent Robin Hood Hashing

Hash tables are fundamental components in software engineering, but optimizing them for modern multicore processors presents significant challenges. Among various open-addressing strategies, Robin Hood Hashing is highly regarded for its serial performance. It works by minimizing the "Distance From expected Bucket" (DFB) for all entries. The algorithm effectively "steals" slots from "rich" entries (those located close to their home bucket) to give to "poor" ones (those far away), ensuring a more uniform distribution of probe lengths and excellent cache locality.

Comparison of insertion strategies: Robin Hood hashing shifts existing elements to minimize distance from home, whereas Linear Probing simply finds the next empty slot.

However, this rebalancing act makes Robin Hood hashing notoriously difficult to implement concurrently. Unlike Linear Probing, where an insertion simply finds the first available slot, a Robin Hood insertion or deletion can trigger a "cascade" of shifts across multiple buckets to maintain the DFB invariant. In a multi-threaded environment, these cascading updates are difficult to coordinate without complex locking strategies that often lead to performance bottlenecks or deadlocks. Existing lock-free alternatives, such as standard Linear Probing, often suffer from "contamination"—where the accumulation of tombstones from deleted entries degrades performance over time.

A Non-Blocking, Obstruction-Free Approach

This paper introduces the first non-blocking, obstruction-free implementation of the Robin Hood algorithm. The proposed solution rests on two primary technical pillars: a multi-word compare-and-swap ($K$-CAS) primitive and a sharded timestamping mechanism for readers.

Atomic Multi-Word Updates ($K$-CAS)

To handle the cascading shifts required by Robin Hood rebalancing, the algorithm employs a $K$-CAS primitive. This allows a thread to update multiple memory locations (buckets) atomically. If any location is modified by another thread during the operation, the entire $K$-CAS fails, and the thread retries. Crucially, the authors utilize a $K$-CAS implementation that is highly portable, requiring only a standard single-word CAS available on most modern CPUs.

Step-by-step visualization of a Robin Hood insertion. The insertion of $V_2$ triggers a cascade of shifts for $Z$ and $W$ to maintain the probe distance invariant.

Efficient Reading via Timestamping

A significant hurdle in concurrent hashing is the "relocation race." If a Contains operation searches for a key while a concurrent Remove operation shifts that key backward, the reader might skip over the key and incorrectly report it as missing. To avoid forcing readers to use expensive $K$-CAS operations, the authors implement sharded timestamps. Readers record timestamps at the beginning and end of their search; if a timestamp changes, indicating a concurrent modification in that region, the search is restarted. This keeps the common Contains path fast and mostly read-only.

Experimental Evaluation

The implementation was stress-tested using synthetic microbenchmarks on a high-end server equipped with four Intel Xeon E7-8890 v3 CPUs, providing a total of 72 physical cores and 144 hardware threads. The benchmarks evaluated the data structure under "Light" (10% writes) and "Heavy" (20% writes) workloads across various load factors (20% to 80%). The table size was fixed at $2^{23}$ entries to ensure it exceeded the CPU cache, forcing the system to deal with realistic memory latency.

Key Results

  • Scalability: The $K$-CAS Robin Hood algorithm demonstrated strong scaling up to 144 threads, consistently outperforming lock-free Linear Probing and Maged Michael’s separate chaining implementation.
  • Cache Efficiency: The implementation successfully preserved the low probe lengths characteristic of serial Robin Hood hashing. It incurred significantly fewer cache misses—often 2x to 4x fewer at high load factors—compared to Hopscotch Hashing or Linear Probing.
  • Stability vs. Hardware Tricks: While Hardware Transactional Memory (HTM) variants showed promise at low thread counts, they suffered from significant performance degradation once HyperThreading was engaged (beyond 72 threads). The software-based $K$-CAS approach remained stable and predictable across the entire range.

Conclusion and Future Work

By combining $K$-CAS for atomic writes and sharded timestamps for fast reads, the authors have created a concurrent Robin Hood hash table that maintains high performance even under heavy load. While the current implementation is obstruction-free—meaning pathological contention could theoretically cause livelock—it provides a robust and portable alternative to lock-based or tombstone-heavy structures. Future work includes integrating concurrent resizing and exploring hybrid models that use HTM for fast-path operations with $K$-CAS as a reliable fallback.

Summary updated

BibTeX
@inproceedings{kelly2018concurrent,
  author = {Robert Kelly and Barak A. Pearlmutter and Phil Maguire},
  title = {{Concurrent Robin Hood Hashing}},
  booktitle = {OPODIS},
  year = {2018},
  doi = {10.4230/lipics.opodis.2018.10},
}
Figure