Object-oriented vs Data-oriented design

Hello guys.
I made a quick visualization about advantages of using data-oriented design with ECS and compare it with regular object-oriented design.
I tried to explain how exactly entity components interact with the CPU cache.
If I miss something - please let me know, I am still learning.

2 Likes

Critique:

  • DOD is about more than just memory layout - it’s about a data first approach (instead of the usually code first approach)
  • Video pacing is a bit off
  • Prefetching plays a big role in why linear memory access is optimal - if the cpu can predict what to fetch while doing operations it does not have to wait for memory
  • Noise vs. useful data in cache/using memory bandwidth missed

Watch this https://www.youtube.com/watch?v=rX0ItVEVjHc

4 Likes

Thank you for your advice.
You are right, prefetching is very important, but I don’t understand how it works for objects. I mean when the data for every object is stored in nearby memory cells. Does prefetcher load needed object data with the noise in advance?
I haven’t completely watched the video you attached, but I ran superficially and didn’t find answers to my question there.

1 Like

For randomly allocated objects I can think of 2 ways

  • speculative execution, which might find pointers to memory to prefetch
  • because it was allocated near recently used other memory (f.i. it might not be in L2 cache but L3 with bigger blocks)

There are probably more but the point is: It does not work for objects* (* reliably), the cpu has to do a lot more work to figure out what to prefetch (or wait for memory)

2 Likes