Data Oriented Design: Introduction

  Рет қаралды 8,174

GetIntoGameDev

GetIntoGameDev

10 ай бұрын

#gamedev #gamedevelopment #programming
Discord: / discord
Playlist: • Data Oriented Design
Code: github.com/amengede/getIntoGa...
Patreon: patreon.com/user?u=58955910

Пікірлер: 23
@franklynotyourbussiness9401
@franklynotyourbussiness9401 10 ай бұрын
Knowing how to store and read 2d arrays in 1d format is the single most useful thing in graphics programming from my experience. It's fast, efficient and so many engines already use these kind of arrays (eg. in vertex buffers, or frame buffers). I remember writing 100% software rasterizer and that was my go-to representation for framebuffer. As for OOP vs DOP: so many beginners try to use OOP in game programming, where it brings more harm than good, just because programming schools and courses focus too heavily on it. It has its usefulness, but the performance overhead can sometimes be a detriment. Not everything needs to be a separate object :)
@tamararoberson8060
@tamararoberson8060 7 ай бұрын
To add, if we remember arrays are basically just pointers, grid[3][4] is not one contiguous chunk of memory but just a list of pointers to the arrays containing the real data. If you flatten the 2D array, it's guaranteed to be contiguous and there's only one pointer to the head involved, so every action in the grid only involves a looking at the offset from the head. Not the double jump in [x][y].
@franklynotyourbussiness9401
@franklynotyourbussiness9401 7 ай бұрын
it also is easier to copy around, since you copy the whole data block and don't have to copy each subtable separately@@tamararoberson8060
@sheepcommander_
@sheepcommander_ 2 ай бұрын
@@tamararoberson8060 ohhhh thanks
@kenb1
@kenb1 9 ай бұрын
Data Oriented Design, if done right, can produce very cpu-friendly code. It's easier to fit the relevant data into the L2/L3 cache, improve branch prediction and avoid cache misses, and also for the compiler to implement SIMD instructions.
@GetIntoGameDev
@GetIntoGameDev 9 ай бұрын
And the holy grail (at least in my opinion), batch up jobs so compute shaders can handle updates etc.
@chbrules
@chbrules 4 ай бұрын
This is beautiful. I used to use C++ back in the day for dev stuff, but now I'm jumping back into binary software dev for fun and I picked up C instead. I'm so happy that I did, as it really lends itself to this sort of data oriented design and being able to really understand what the memory management is doing. I'm planning to use RayLib to write a little 2D RPG for fun to practice my skills, and this sort of design philosophy is really going to be wonderful and efficient!
@CoryWheeler-df4dm
@CoryWheeler-df4dm 10 ай бұрын
That was a brilliant explanation! Thank you!
@ArthurSchoppenweghauer
@ArthurSchoppenweghauer 10 ай бұрын
Awesome demonstration. I've always had the suspicion that OOP was kinda fluffy academic language stuff and was never really tested for performance. Makes me think about how much better a lot of software could be were it not written according to programming paradigms that ignore the memory layout of the computer.
@GetIntoGameDev
@GetIntoGameDev 10 ай бұрын
Agreed, especially python. Those pointer accesses are super expensive.
@konev13thebeast
@konev13thebeast 15 күн бұрын
OOP is great for standard business software where readability and adaptability are the most important parts. Performance sensitive work, not at all
@EveryOtherDayTV
@EveryOtherDayTV 4 ай бұрын
Great video!
@drewdraw0
@drewdraw0 9 ай бұрын
Great video! Super clear and helpful explanation of the difference between the two paradigms. Do you have a sense for how much of the speedup is due more to numpy handling a lot of the calculation and memory management vs. a more objective measure of the two algorithms' efficiency. Not sure how much pure python you were using in the version at the beginning of the video, but that could explain a lot of the difference depending. Regardless it's a great example of how to use numpy to good effect if you're writing anything in Python that can be expressed as numerical data.
@GetIntoGameDev
@GetIntoGameDev 9 ай бұрын
Thanks! I'm not sure what's meant by "a more objective of the two algorithms' efficiency", as data oriented design is meant to take cache lines into account, this isn't a factor in traditional algorithm analysis anyway. Nonetheless I understand your point, I'm currently working on a higher level example to compare. Regarding the issue of "Yeah but this is just numpy", my perspective would be: then use numpy! It runs in python and basically does lists faster (since it stores the data directly in memory without layers of pointer indirection). Even using regular numpy without compilation I got a 10x speedup, which is encouraging. Now the question of whether there's anything in python which can't be expressed in numerical data is sort of philosophical. I'd argue it's always possible to recast a problem as purely numerical. Even callback functions can be indexed as arrays of function references. Just my opinion though.
@hetias
@hetias 10 ай бұрын
Nice video! There was always something misterious about DOD for me because of me not finding many examples, atleast not as clear as this one. I started making a project thinking on "DOD mode" but now i see that i failed completly, anyway, gonna refactor all that. Another thing, i understand that DOD it's more efficient because it maps better the data for the cpu right? Most of what i reed or watched was really more oriented to low level languages and how the cpu had a better time with it, but seeing something like this in python it's really interesting, and shows me how impactful it can be independent of the language (ngl i would be the kind of guy that makes fun of python for being slow, now my mouth is shut)
@GetIntoGameDev
@GetIntoGameDev 10 ай бұрын
Clearly no one told python it was meant to be a slow language 🤣
@ThePiones
@ThePiones 6 ай бұрын
Good stuff, actually understood what this buzzword was about.
@CaptTerrific
@CaptTerrific Күн бұрын
I'm truly perplexed how this affected performance in any direction except negatively... please help :) What was described on paper, putting every single cube and transformation into a single class of multiple arrays, shouldn't be any different from having each in an array in a different class - the objects of that class should still be references to their components, with each pointer still being O(1) since there are no list traversals, and each object in the heap would be stored contiguously. And given the size of the arrays we'd expect from all transformations, unless we preallocate a HUGE amount of memory space, we're still going to be hindered (speed and cache misses) by the single virtual memory space being separated throughout the core. If, instead, you're truly creating a single OBJECT with all of the cubes and transformations in a single set of arrays, I'd expect the still constant time calculation of the indices for lookup to be at least twice as computationally intensive as pointing directly to them. Not to mention - if this is all a single array - what this would do to insertion and removal times! Even implementing with a search tree instead of an array should still be slower, if I'm understanding this correctly (which I am clearly not :D) Is this just a python thing, to trick the interpreter into doing what you want? I've never done graphics programming, and I know nothing about how Python works under the hood... someone please explain what I'm getting wrong here :)
@CaptTerrific
@CaptTerrific Күн бұрын
So, per usual, I should have just watched the full video before commenting... but my questions are still somewhat relevant (maybe?). It seems your implementation makes perfect sense here, since you're using a small, set number of cubes with a set number of transformations mapped 1:1. I'm curious if this 1) scales with thousands of objects, and/or 2) remains efficient with frequent additions/removals?
@GetIntoGameDev
@GetIntoGameDev 14 сағат бұрын
I don’t remember exactly what implementation I went with here, from memory this should scale decently for more objects but needs some modification to actually be useful within a more complicated system. There will be certain thresholds at which one approach beats another. Currently I’m going with an ordered array and binary search lookup for my engines, but this is prefaced on the idea that I’ll be searching data a lot more than adding/deleting. Beyond a certain size a hashmap would probably perform better.
@Gorgutzdaboss
@Gorgutzdaboss 5 ай бұрын
Wouldn't it be easier to read/handle if the fields that are used often together be in a struct instead of in multiple arrays? I understand that by exploding everything, it's easier to just pick and choose what data you need, but I'm concerned about the performance if you have to handle multiple huge arrays in a tight loop.
@JChen7
@JChen7 8 ай бұрын
Feels like a fancy term for a glorified logical extension of "unwrapping the loop" solution for performance.
@JustFor-dq5wc
@JustFor-dq5wc 3 ай бұрын
DOTS handle CPU bottlenecks. I'm using DOTS when needed. OOP is much better for more complex problems (like Behaviour trees etc.)
Data Oriented Design: Database Normalization
12:45
GetIntoGameDev
Рет қаралды 1 М.
Não pode Comprar Tudo 5
00:29
DUDU e CAROL
Рет қаралды 82 МЛН
McDonald’s MCNUGGET PURSE?! #shorts
00:11
Lauren Godwin
Рет қаралды 29 МЛН
Monster dropped gummy bear 👻🤣 #shorts
00:45
Yoeslan
Рет қаралды 10 МЛН
Object Oriented Programming is Good | Prime Reacts
31:30
ThePrimeTime
Рет қаралды 275 М.
Data-Oriented Programming in Java
31:39
Java
Рет қаралды 18 М.
Entity Component Systems - Nico Schoeman
11:57
bbdtv
Рет қаралды 7 М.
8 Design Patterns EVERY Developer Should Know
9:47
NeetCode
Рет қаралды 965 М.
Data-Oriented Programming - Inside Java Newscast #29
8:24
Data-Oriented Demo: SOA, composition
1:32:47
Jonathan Blow
Рет қаралды 152 М.
C++ Crash Course: Data Oriented Design
13:12
CoffeeBeforeArch
Рет қаралды 23 М.
The purest coding style, where bugs are near impossible
10:25
Coderized
Рет қаралды 806 М.
CppCon 2014: Mike Acton "Data-Oriented Design and C++"
1:27:46
Why I removed Components from my Game Engine
13:07
Joshua Manton
Рет қаралды 31 М.
Não pode Comprar Tudo 5
00:29
DUDU e CAROL
Рет қаралды 82 МЛН