What does game dev optimization look like? When I was in college, one of my professors told the class: Do not optimize code because the compiler is smarter than you. He was wrong. As an example, here is the timeline of a frame from Uncharted 2 (my old gdc talk).
The SPUs are mostly fully occupied. For context, anything in blue was hand-optimized by the ICE team. Everything in RED was hand-optimized by the game team. And the rest was optimized to various degrees. Without hand-optimization, we wouldn't have fit in frame.
Here's an example of what it looked like. The first step is to vectorize the code. On PS3, we generally got a 4x to 8x speedup from vectorization on SPU. On modern pcs, it varies by application but I tend to get 2x perf from manually vectorizing code. YMMV.
The next step was to lay out all the instructions in order, keeping track of the latency. SPUs could dual issue one even and odd instruction per cycle, and since there was no cache all memory loads/stores took the exact same amount of time.
The next step was to software pipeline the code. The {} was a comment, where e6:1 means even instruction, 6 cycle latency, and runs from iteration 1 in the loop. This way we could run the loop with no stalls. On SPUs, this generally gave us a 2x improvement after vectorization.
It was a rare time where such hyper optimization netted notable wins. But game devs constantly optimize vectorize code wherever bottlenecks may be. If you think game devs don't optimize code that beats the compiler, then I don't really know what to tell you.
Share this Scrolly Tale with your friends.
A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.
