r/cpp • u/igaztanaga • May 18 '26
Neoclassical C++: segmented iterators revisited (1)
Hi,
I've written a blog post revisiting Matt Austern's great Segmented Iterators and Hierarchical Algorithms paper (2000) and benchmarking an experimental implementation I've been playing with in Boost.Container.
Quick idea: std::deque and friends are internally segmented (blocks of contiguous memory), but STL-like iterators hide that, so every ++it has to check for a block boundary. Austern's proposal splits the iterator into a segment_iterator (walks blocks) + local_iterator (inside one block), so algorithms can run a tight loop per block and only do bookkeeping at the boundaries.
I benchmarked several "simple" STL algorithms on a Boost deque, and the speedup is way bigger than Austern's original estimation when modern auto-vectorizers enter the game.
Article link: https://boostedcpp.net/2026/05/18/neoclassical-c-segmented-iterators-revisited-1/
Happy to receive feedback!
View all comments
Show parent comment
5
u/igaztanaga May 19 '26
Certainly ABI stability has pros and cons. Probably for std algorithms this is not an issue, since libc++ has managed to implement segmented algorithms (as an internal feature, not intended for custom containers).
There other alternatives to speed up common cases:. libstdc++ specializes several std algorithms for std::deque, MS STL has some vectorization paths for special, scalar types...
But there is no common, public approach that allows writing a custom segmented container with great performance in all std implementations.