More Related Content Similar to Data oriented design Similar to Data oriented design (8) Data oriented design7. class Bot { Vector3 position; … float mod; … float aimDirection; … voidUpdateAim(Vector3 target) { aimDirection = Vector3.DotProduct(position, target) * mod; } } 8. class Bot { Vector3 position; … float mod; … float aimDirection; … voidUpdateAim(Vector3 target) { aimDirection = Vector3.DotProduct(position, target) * mod; } } Icache-miss 9. class Bot { Vector3 position; … float mod; … float aimDirection; … voidUpdateAim(Vector3 target) { aimDirection = Vector3.DotProduct(position, target) * mod; } } Icache-miss data-miss 10. class Bot { Vector3 position; … float mod; … float aimDirection; … voidUpdateAim(Vector3 target) { aimDirection = Vector3.DotProduct(position, target) * mod; } } U N U S E D Icache-miss data-miss 12. Array of Structures Structure of Arrays class Bot { Vector3 position; … float mod; … float aimDirection; … } List<Bot> bots; class Bots { List<Vector3> positions; … List<float> mods; … List<float> aimDirections; … } 13. class Bot { … voidUpdateAim(Vector3 target) { aimDirection = Vector3.DotProduct(position, target) * mod; } } class Bots { … staticvoidUpdateAims(List<float> aimDirections, List<Vector3> positions, List<float> mods, List<Vector3> targets) { for (uint i = 0; i < aimDirections.Count; ++i) aimDirections[i] = Vector3.DotProduct(positions[i], targets[i]) * mods[i]; } } 16. It’s all about memory Optimize for data not code Most code is mostly bound to memory access 17. It’s all about memory Optimize for data not code Most code is mostly bound to memory access Not everything needs to be an object