3 ms·
You’ve missed a lot of important real world details about what’s going on in the system, which is the heart of what Mike Acton talks about. > Say what? In C++,
by dottrap 10y ago
You’ve missed a lot of important real world details about what’s going on in the system, which is the heart of what Mike Acton talks about.
> 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).