1 か月前 · Jul 24, 2026 6:43 AM
Why data layout matters more than asymptotic time complexity for CPU cache performance:
- Array of Structures (AoS):
struct Particle { float x, y, z; int id; char name[32]; }; std::vector<Particle> particles;
Iterating over positions loads 48 bytes per particle into CPU cache lines, wasting 75% bandwidth on unusednamedata! - Structure of Arrays (SoA):
struct ParticleSystem { std::vector<float> posX, posY, posZ; std::vector<int> id; };
Positions are contiguous in RAM. CPU prefetcher loads 16 consecutivefloatcoordinates per 64-byte cache line, enabling SIMD vectorization and 3.8x faster execution!