r/cpp • u/TheCrush0r • Jun 07 '26
Recent LLVM hash table improvements
https://maskray.me/blog/2026-06-07-recent-llvm-hash-table-improvements
83
Upvotes
r/cpp • u/TheCrush0r • Jun 07 '26
9
u/g_0g Jun 07 '26
Interesting article, but still a bit unclear about what are all the criteria for LLVM usage.
It's mentioned that the Abseil impl (with its default hash I guess) "leads to inferior performance", which is surprising seeing these probes-mean numbers*.
For Boost it's "each instantiation drags in more code", which is weird because they are all template-based (so adding to that binary size anyway, right?)
And more generally, "Swiss Table family implementations are poor at small keys", which relates to... memory overhead from metadata? Performance? Code size?
*Probes-mean around 1.55 for find-hit seems quite high to me. A flat map with a good hash should be around 1.1, even at high load (~1.2 for find-miss, see here). Find-hit being higher than find-miss is also odd. I would definitively monitor max probe length too, to detect bad drift in worst case scenarios that comes with linear probing...
8
u/realestLink Jun 07 '26
What's the rationale for moving to linear probing from quadratic probing?
5
u/ReDr4gon5 Jun 07 '26
So this was all measured using instrumented clang. Any reason this was not done with a profiler?
2
u/matthieum Jun 07 '26
For context, buried in the middle of the article:
There's a table with way more details there, in which we can notably see for the most used types how many times the table grows, or the peak size.
In any case, it's clear that this is not a "balanced" usage, against which generic hash-tables are likely to be tuned. The low rate of erasure makes backwards shifting deletion more appealing, for example.
I do wish there was a link to said Algorithm R, though. I don't have TAOCP (woe me), and looking for Algorithm R on google I could only find discussions of Reservoir Sampling (from Volume 2).
In particular, at the end of the article the author mentions that backwards shifting deletion with Robin Hood Hashing requires re-calculating the hashes or saving displacement, which I take to mean that Algorithm R doesn't... but then I wonder how Algorithm R is supposed to work. Guess I'll need to fine time to dive into the code.
0
u/[deleted] Jun 07 '26
[deleted] β view deleted comment