Hacker News new | ask | show | jobs
by skavi 1485 days ago
A good way is to have your data arranged in structs of arrays rather than in arrays of structs. This allows the compiler to generate code which just loads in linear sections of memory to SIMD registers. It’s also just more cache efficient in general.

Check out data oriented design if you aren’t already familiar.

2 comments

Note that sometimes it's sufficient to have arrays of structs of arrays. That is you don't need to necessarily go whole hog.
That very much depends on access patterns. If you’re performing an operation I’ve ever object with a certain field, struct of array makes sense. If you’re doing an operation which uses many fields on some arbitrary dynamic randomly ordered subset of objects, then array of structs will yield better because at least you recover some memory locality.