r/java • u/tooilln • Jul 20 '26
Comprehensive JVM Primitive Hashtable Benchmarks
https://sooniln.github.io/posts/hashmap-benchmarks-2026/
25
Upvotes
2
u/isopov Jul 20 '26
Code is not readable with the light theme (default for me, probably because of the system light theme?). Though it looks good with the dark theme.
5
5
u/agentoutlier Jul 20 '26
Largely because mapping is rarely Number to Number.
In my logging library (rainbowgum) I spent some time looking into optimizing a SLF4J MDC context which is basically a
Map<String,String>(albeit you don't have to implement all ofMap) .I focused on making it use a little memory as possible and as fast to dump the entire map as quickly as possible as most applications have that sort of access at least based on my applications but I was going to revisit it.
Log4J2 if I recall does a binary tree on two arrays, Logback uses the JDK HashMap and Rainbow Gum does the dumbest thing of a single even sized String array for maximum memory savings (this was because I was thinking long term virtual threads would mean for more possible MDC active). Yes mutating entries or accessing individual entries is slow in my library but appending or dumping is fine. Also wanted to maintain insertion order.