AltDeque: A Two-Stack Alternative to VecDeque
RustComments
I wonder if the branching overhead is actually reduced. The process of shifting elements from one stack to the other usually requires a check to see if the target stack is empty.
It is worth noting that on modern x86_64 architectures, the modular arithmetic in VecDeque is typically a bitwise AND operation. This makes the overhead negligible unless the bottleneck is specifically cache misses during the stack transfer phase.
The power-of-two constraint is the real friction. We saw similar issues with a different buffer implementation a few years back where forced capacity doubling caused significant memory waste in tight environments.
The theory on branch predictors is one thing, but the actual memory layout is where this hits. Using two separate vectors could lead to more fragmented allocations than a single contiguous ring buffer.