A % whose divisor the compiler cannot see is a real integer division, far slower than the arithmetic around it, on a path that is meant to be a handful of instructions. When capacity is a power of two, index & (capacity - 1) gives the same answer in one instruction. That is why the Linux kernel's circular buffer helpers, the CIRC_CNT and CIRC_SPACE macros, are defined only for power-of-two buffers, and why the LMAX Disruptor rejects a ring size that is not one. It also makes the never-wrapping counter form safe: an unsigned counter that rolls over at 2^32 lands exactly where the mask expects, because the capacity divides 2^32, so tail - head is still the correct count. In C or C++, declare those counters signed instead and the overflow is undefined behaviour, which is the classic bug in hand-rolled ring buffers.