News for hackers. Stuff that matters.
Re:Saving a Third of Our Memory by Re-Ordering Go Struct Fie... by onphonenow on Sunday January 09, 2022 @10:40PM (#29870320)
per 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.

There are no comments on this comment yet.