r/cpp • u/sporacid • Mar 21 '26
Slot map implementation for C++20
I've just finished submitting the initial version of my slot map implementation, based on this post. A slot map is a data structure that provides stable and versioned keys to stored values. Inserting into the map creates and return a unique key, which stays valid until the slot is explicitly freed.
I hope someone will find this useful :)
https://github.com/sporacid/slot-map
EDIT: As suggested by some of you, I've added benchmarks to compare to plf::colony. As i did those benchmarks, I had to work on a bunch of optomizations to compete, and I've introduce a static storage that has a fixed number of slots, and I kept the original dynamic storage with a fixed number of blocks, but the blcoks are allocated as needed. Let me know what you think!
View all comments
Show parent comment
2
u/EstablishmentHour335 Mar 27 '26
They are interesting benchmarks, although there is a couple of things that could be done to make them more informative, Matthew Bentley (plf::colony creator) has a good writeup (https://plflib.org/blog.htm 24-12-2024 - A few tips for correct benchmarking).
I would especially benchmark them separated into their own programs, rather than compiled into the same executable. I noticed with the static slot map especially, it would alter the performance of the other containers when compiled into the same executable in my testing.
Another thing is, I would test sparsity and fragmentation, plf::colony is supposed to be good at that.
I actually got really interested in the static slow map, what exactly is it doing at compile time? It does bloat my compile times with huge element counts, but it has really great performance.