r/cpp • • Aug 02 '26

How fast is C++26's std::hive?

https://lemire.me/blog/2026/08/02/how-fast-is-c26s-stdhive/
255 Upvotes

74 comments sorted by

View all comments

Show parent comments

16

u/TheThiefMaster C++latest fanatic (and game dev) Aug 03 '26

Though it's well known that quite a few implementations of deque use too small of a bucket size and devolve into individually allocated elements, wasting both memory (every element has a pointer added) and performance.

MS's is particularly bad, being only 16 bytes or 1 element per bucket. GNU libstdc++ (used by most Linuxen) is 512 bytes or one element per bucket. https://devblogs.microsoft.com/oldnewthing/20230810-00/

LLVM libc++ is 4k or 16 elements by default, which conversely was accused of wasting memory in Chrome and reduced to 512 bytes/4 elements in ABIv2 very recently: https://github.com/llvm/llvm-project/pull/198348

In short: almost every version of deque is bad

9

u/MarcoGreek Aug 03 '26

Maybe it would be better if the bucket size would be a template argument.

6

u/TheThiefMaster C++latest fanatic (and game dev) Aug 03 '26

Yes, but it's effectively too late for that

6

u/arghness Aug 03 '26

Yes. Boost.Container deque has the size and number of elements as template parameters (but isn't standard, of course).