Data oriented design

1,029 views
901 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,029
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Data oriented design

  1. 1. Data-Oriented Design<br />@Neku42<br />max.klyga@gmail.com<br />
  2. 2.
  3. 3. Unreasoned<br />OOD<br />
  4. 4.
  5. 5. PROGRAM<br />DATA<br />DATA<br />
  6. 6. Good code follows good data, not the other way around.<br />
  7. 7. class Bot<br />{<br />Vector3 position;<br />…<br />float mod;<br />…<br />float aimDirection;<br />…<br />voidUpdateAim(Vector3 target)<br /> {<br /> aimDirection = Vector3.DotProduct(position, target) * mod;<br /> }<br />}<br />
  8. 8. class Bot<br />{<br />Vector3 position;<br />…<br />float mod;<br />…<br />float aimDirection;<br />…<br />voidUpdateAim(Vector3 target)<br /> {<br /> aimDirection = Vector3.DotProduct(position, target) * mod;<br /> }<br />}<br />Icache-miss<br />
  9. 9. class Bot<br />{<br />Vector3 position;<br />…<br />float mod;<br />…<br />float aimDirection;<br />…<br />voidUpdateAim(Vector3 target)<br /> {<br /> aimDirection = Vector3.DotProduct(position, target) * mod;<br /> }<br />}<br />Icache-miss<br />data-miss<br />
  10. 10. class Bot<br />{<br />Vector3 position;<br />…<br />float mod;<br />…<br />float aimDirection;<br />…<br />voidUpdateAim(Vector3 target)<br /> {<br /> aimDirection = Vector3.DotProduct(position, target) * mod;<br /> }<br />}<br />U<br />N<br />U<br />S<br />E<br />D<br />Icache-miss<br />data-miss<br />
  11. 11. …<br />…<br />…<br />…<br />…<br />…<br />
  12. 12. Array of Structures<br />Structure of Arrays<br />class Bot<br />{<br />Vector3 position;<br />…<br />float mod;<br />…<br />float aimDirection;<br />…<br />}<br />List<Bot> bots;<br />class Bots<br />{<br />List<Vector3> positions;<br />…<br />List<float> mods;<br />…<br />List<float> aimDirections;<br />…<br />}<br />
  13. 13. class Bot<br />{<br />… <br />voidUpdateAim(Vector3 target)<br /> {<br /> aimDirection = Vector3.DotProduct(position, target) * mod;<br /> }<br />}<br />class Bots<br />{<br />… <br /> staticvoidUpdateAims(List<float> aimDirections,<br />List<Vector3> positions, List<float> mods, List<Vector3> targets)<br /> {<br /> for (uint i = 0; i < aimDirections.Count; ++i)<br />aimDirections[i] = Vector3.DotProduct(positions[i], targets[i]) * mods[i];<br /> }<br />}<br />
  14. 14. Know the data!Think! Think! Think!<br />
  15. 15. It’s all about memory<br />Optimize for data not code<br />
  16. 16. It’s all about memory<br />Optimize for data not code<br />Most code is mostly bound to memory access<br />
  17. 17. It’s all about memory<br />Optimize for data not code<br />Most code is mostly bound to memory access<br />Not everything needs to be an object<br />
  18. 18. Data-Oriented Design:<br />Better performance<br />
  19. 19. Data-Oriented Design:<br />Better performance<br />Often simpler code<br />
  20. 20. Data-Oriented Design:<br />Better performance<br />Often simpler code<br />More parallelizable code<br />
  21. 21. Questions?<br />
  22. 22. http://slidesha.re/hKF9er<br />

×