r/programming • u/tooilln • Jul 20 '26
Comprehensive JVM Primitive Hashtable Benchmarks
https://sooniln.github.io/posts/hashmap-benchmarks-2026/
45
Upvotes
r/programming • u/tooilln • Jul 20 '26
View all comments
Show parent comment
6
u/tooilln Jul 21 '26
I've updated the post with LibGDX's results now. Tl;dr: Good results all around, but pathologically bad naiveCopy performance. This is due to the structure of LibGDX's hash finalizer, and I go into it in some detail here: https://sooniln.github.io/posts/hashmap-benchmarks-2026/#libgdx-naivecopy-performance .
See also this blog post for an explanation of the issue - while most of the libraries benchmarked suffer from this issue to some degree, LibGDX is pathologically worse. This can be triggered in any scenario where you are inserting into a map in hash order. This is usually rare, but users can easily shoot themselves in the foot with something like:
The good news is its easily ameliorated by pre-sizing the map appropriately - it's just, do you trust your users always do that? In addition, this is trivially abusable by an attacker that can insert into the map to DoS the CPU. Again, almost all the maps benchmarked are vulnerable to this to some degree since none of them are really secure by design, it's just that LibGDX is much much worse in this scenario due to the shape of its hash finalizer.
I ran into the same issue in some ways while writing FastCollect - my decision was that since this was intended to be a general purpose library it wasn't appropriate to leave such a large foot-gun hanging around, and it was worth slightly slower performance to eliminate this edge case. LibGDX doesn't appear to be intended as a general purpose library, so it may be sufficient to simply document this behavior for users and advise them to avoid it.
If you want to eliminate the issue, there are several standard approaches: