3 ms·
per https://jonasdevlieghere.com/order-your-members/ https://jonasdevlieghere.com/order-your-members/ Smaller size is good for cache, but other factors matter
by onphonenow 5y ago
per https://jonasdevlieghere.com/order-your-members/ https://jonasdevlieghere.com/order-your-members/
Smaller size is good for cache, but other factors matter
From the above
Single-Threaded Environment
When a single thread on a single core is accessing the data in a struct, we can improve caching performance by using as little cache lines as possible.
By optimizing for memory footprint, as discussed in the previous section, the struct uses less memory and hence occupies less space in the cache.
By placing heavily used members close together, we hope (based on the locality of reference principle) that they will end up closer together in the cache, preferably even on the same cache line, and hence use less cache space.
By separating hot fields form cold ones, we reduce the amount of cache lines filled with unused data.