4 ms·
Why is having head and tail in the same cache line bad for performance? Given that the code reads both head and tail to check if the queue is empty, being in th
by anthomtb 4y ago
Why is having head and tail in the same cache line bad for performance? Given that the code reads both head and tail to check if the queue is empty, being in the same cache line seems optimal.
- anthomtb 4y agohttps://rigtorp.se/ringbuffer/ https://rigtorp.se/ringbuffer/, from a comment below, answered my question. In rough terms, every push or pop from the queue also causes head or tail to be written, thus dirtying a line of cache. That’s the bit I misunderstood.
- binarycoffee 4y agoTo be clear, as mentioned in another thread [0] there is no need to ensure consistency between head and tail for a SPSC so storing them in different cache lines would be much better. For the multiple-consumer variant, however, consistency between head and tail is required so packing them in the same atomic is the simplest solution. [0] https://news.ycombinator.com/item?id=31386741 https://news.ycombinator.com/item?id=31386741