> Say what? In C++, you'd simply create another object that is another instance of the Rocket class. Behold, "more than one".
So now you have a bunch of separate instances of rockets which are probably scattered throughout heap memory which will lead to cache misses on every access. Mike is describing the lost optimization potentials here because you didn’t think to reason about how you will use this data.
A simple example, every rocket needs to update its position every frame and probably obeys a velocity equation defined in the game. Iterating through every rocket scattered out through heap memory is already going to kill you with cache misses. But additionally, since all the rockets obey the same equation, we should be using SIMD to compute everything which can let us do 4x-16x operations (or more depending on hardware) for the same cost as doing one. But chances are your Rocket class ivars are not nicely laid out for SIMD (AoS vs. SoA), so you will be forced to copy or swizzle a bunch of data which negates the performance benefits you are trying to win with SIMD. If you designed your data upfront with this idea in mind (many rockets for batch operations), then you get both cache optimization wins and SIMD wins, and now we are talking about speed ups that can be easily 10x-100x. And we haven’t even touched the possibility of further parallelizing this across multiple cores.
A real world example they gave at GDC on SIMD was a many-players-to-many-doors problem they had to solve. On every frame, any player near any door had to automatically open like in Star Trek. 30 doors and 100 players means they have 3000 tests they have to run. The original algorithm wasn’t data oriented and what Mike Acton would probably call typical C++ BS: A single Door class. On strict CPU budgets to handle everything else in the game, the cache misses alone were worrisome. In the talk they (obviously) convert to SIMD with the idea of ‘many’ using Data Oriented Design (which also solves the cache miss problem). They got a 20x-100x speed up (depending on the number of players and doors).
It helps to think about relational databases (and there, why are column stores much faster for many tasks).
Probably true.
> With no regard at all for what data tranformation is really being done, or for the layout of the data.
I agree that OO design is usually not done with regard for the layout of the data.
> Or for that matter, without the basic understanding that where there's one thing, there's probably more than one.
Say what? In C++, you'd simply create another object that is another instance of the Rocket class. Behold, "more than one".
> Though there are a lot of performance penalties for this kind of design, the most significant one is that it doesn't scale. At all. One hundred rockets costs one hundred times as much as one rocket.
Well, see, one hundred rockets have one hundred times the data that one rocket has. I don't see how you can avoid that, no matter how you represent the data or whether you do it as OO or something else.
But you don't duplicate the code 100 times, just the data. You might also have 100 instances of a pointer to a virtual function table, which means you've wasted 100 times the size of one pointer. That's not impressing me with the inefficiency here.
So you can color me unimpressed with this whole argument on lie #2.