3 ms·
Struct packing has its points for small structs. Indeed, you can reduce cache use and increase cache locality. However for large structs, page aligned structs,
by CalChris 4y ago
Struct packing has its points for small structs. Indeed, you can reduce cache use and increase cache locality. However for large structs, page aligned structs, the cache lines will be constrained to a particular set. Moreover, pointer following from struct to struct can incur a TLB hit; the TLB is another small cache. So while you may cleverly encode things to squeeze size, you may then watch things slow to a crawl.
You are packing small structs in order to squeeze lots of them into the caches. However for large structs, you should at least consider refactoring them into small structs which you can then pack to your heart's content.