std::deque
stores elements in "buckets" (arrays) of fixed size. Different compilers use different bucket sizes:
- MSVC: 16 bytes or element size if it's bigger
- GCC: 512 bytes or element size if it's bigger
- Clang:
element_size < 256 ? 4096 : element_size * 16
For MSVC (especially) and GCC, if the deque element size is bigger than the hardcoded size, std::deque
turns into a convoluted std::list
with performance penalties in the majority of cases.
Clang does better in my opinion, no matter what the size of the deque element, the bucket will be at least 16 elements. Though the minimal bucket size of 4096 bytes can be sub-optimal in some cases for small elements.
Why doesn't std::deque
have an additional template parameter for bucket size with the default value of what the vendor thinks is reasonable? This wouldn't break backward compatibility but would allow performance optimisation.