r/cpp • u/Double_Ad641 • Jun 27 '26
Data Access Patterns That Makes Your CPU Really Angry
https://blog.weineng.me/posts/slowest_add/I tried to find the slowest possible way to sum up integers in an array
114
Upvotes
5
u/frnxt Jun 28 '26
That is an interesting exploration! Any idea about the impact of having to lookup the index in a separate array at runtime vs having the memory layout being fixed at compile-time? I would expect the impact to be relatively minimal with modern processors, but compiler optimizing into SIMD instructions might throw a wrench into that.
3
u/mikeblas Jun 28 '26
What about reverse linear?
66
u/_Noreturn Jun 27 '26
You haven't found the newest one asking chatgpt to sum every int
27
u/LegitBullfrog Jun 27 '26
I won't believe you until you test every possible permutation of positions a statistically significant number of times.
7
u/Sopel97 Jun 27 '26
I wonder if it could be made worse by further randomizing the order at each level (or at least at the level with largest jumps), in case there is still some prefetching happening?
2
u/User_Deprecated Jun 28 '26
ran into something like the stride-8 pattern with a message buffer pool. slots were page-aligned and field lookups kept hitting the same L1d sets. offsetting by a weird number fixed it.
-19
u/[deleted] Jun 27 '26
[removed] — view removed comment