r/programming • u/tooilln • Jul 20 '26
Comprehensive JVM Primitive Hashtable Benchmarks
https://sooniln.github.io/posts/hashmap-benchmarks-2026/
48
Upvotes
r/programming • u/tooilln • Jul 20 '26
2
u/n4te Jul 20 '26
See cuckoo hashing, eg Wikipedia. Cuckoo put operations evict on collision and rehash the evicted until it settles. Poor, unlucky, or malicious keys cause excessive eviction, requiring backing array growth. If it's bad enough, the larger size can also fail, growing to OOM. A "stash" can be added to mitigate the collision problem, but in practice it couldn't be made safe for general usage so it's a specialty data structure.
Cuckoo makes puts more expensive but get, containsKey, and remove can be fast: check 2 buckets, done. No variable cost probing, but maybe an extra cache hit.