3 ms·
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 li
by skavi 4y 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.
- djmips 4y agoNote that sometimes it's sufficient to have arrays of structs of arrays. That is you don't need to necessarily go whole hog.
- ummonk 4y agoThat 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.