Re:Getting 4 bytes or a full cache line: same speed or not?
by corysama on Wednesday August 01, 2018 @02:18PM
(#17665302)
Additionally, if you do the wait for a byte, you've done 90% of the wait for 63 adjacent bytes. Software becomes memory bound when it peeks at 4 bytes here, 4 bytes there in zillions of unpredictable cache lines. So, instead of waiting 41 cycles to process 64 bytes, it waits 300 cycles to process 4.
It helps to think of the * and -> operators in C++ as "int cache64BytesAndLoad4FromCache(int *p);" That's when you start to really feel "int x = a->b->c->d; a = a->next;" deep in your gut.
A potential order of magnitude improvement hiding in the memory access patterns of your code makes this worthwhile information for a lot of devs.