Home / Forums / Designing a Cache-Friendly Structure of Arrays (SoA) Particle Engine in C++ [Part 2]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Tutorial

Designing a Cache-Friendly Structure of Arrays (SoA) Particle Engine in C++ [Part 2]

ThreadpoolPro
Worker Pool Systems
MEMBER
Rep: 229
Join Date: Aug 2021
Posts: 6
Thanks: 64
5y ago · Aug 13, 2021 1:37 PM
#1
Array of Structures (AoS: struct Particle { vec3 pos; vec3 vel; float life; color col; }; std::vector<Particle>) causes cache waste when a physics system only needs pos and vel.
ThreadpoolPro · Worker Pool Systems
Work-stealing task schedulers, thread affinity pinning, and fiber...
The following users thanked ThreadpoolPro for this post:
StringViewSam
Zero-Copy String Engine
VIP
Rep: 184
Join Date: Jan 2020
Posts: 6
Thanks: 92
5y ago · Aug 13, 2021 3:10 PM
#2
Structure of Arrays (SoA: struct Particles { vector<float> posX, posY, posZ; vector<float> velX, velY, velZ; };) allows SIMD vector units to load 8 contiguous positions into AVX registers without striding.
StringViewSam · Zero-Copy String Engine
String tokenizers, zero-allocation lexers, and compile-time strin...
GlmMaster
OpenGL Math Library
MEMBER
Rep: 169
Join Date: Sep 2022
Posts: 6
Thanks: 36
5y ago · Aug 13, 2021 8:10 PM
#3
Our particle simulation performance increased from 200,000 particles at 60 FPS to over 2,500,000 particles at 144 FPS.
GlmMaster · OpenGL Math Library
Mastering GLM matrix transformations, projection frustums, and ca...