[HN Gopher] Cache line alignment in C++ - How it makes your prog...
___________________________________________________________________
Cache line alignment in C++ - How it makes your program faster
Author : mfiguiere
Score : 36 points
Date : 2023-09-16 18:59 UTC (4 hours ago)
(HTM) web link (ryonaldteofilo.medium.com)
(TXT) w3m dump (ryonaldteofilo.medium.com)
| userbinator wrote:
| Alignment and other optimisations that increase size tend to show
| their greatest benefit in microbenchmarks, but as the size of the
| data increasingly doesn't fit in the cache, you'll find that the
| increased cache misses will start decreasing performance.
| vvanders wrote:
| That's highly dependent on access patterns and domain space.
|
| When I was optimizing for render sorting on mobile hardware we
| knew we would never see 2k+ drawcalls and cache aware tuning
| gave us huge end-user facing benefits.
| SmoothBrain12 wrote:
| Exactly. I find splitting your struct into 2 structs based on
| memory access patterns(1 used all the time and the other for
| data) is a huge win.
| a_e_k wrote:
| I've long had the idea for trying to write a Valgrind tool to
| help with this by analyzing struct usage. Something to
| profile how hot and cold the various fields of my structs
| are, and also to correlate which fields in a struct are
| frequently accessed together (i.e., within N cycles of each
| other). A tool for the profile part of "profile before
| optimizing" to go with the optimizations you mentioned.
|
| I'm not sure how feasible this is. But if someone else wants
| to steal this idea and implement it for me, be my guest. :-)
| eddtests wrote:
| gcc has some compiler arguments to automate this from what I
| understand (-falign) https://gcc.gnu.org/onlinedocs/gcc/Optimize-
| Options.html
| rsaxvc wrote:
| Currently those GCC flags are only about instruction alignment.
| The article shows a simple example of runtime data alignment.
___________________________________________________________________
(page generated 2023-09-16 23:01 UTC)