8654 shaares
191 private links
191 private links
Instead of
const Thing = struct {
checksum: u128,
number: u32,
flag: u8,
};
use
const SoA = struct {
checksum: []u128
number: []u32,
flag: []u8,
};
in certain circumstances:
- Reduced memory usage due to amortized padding. As flag is a byte, it requires some padding to align with larger fields like checksum.
- Better memory bandwidth utilization for batched code. If a loop needs to process all things, but the processing doesn't require all fields (at least for the majority of objects), then an array-based representation reduces the amount of data that needs to be loaded.