Ok so my shmup prototype is firing a lot of bullets now and I'm seeing that it is slowing down so I tried sampling the app with Instruments but sincerely I didn't make heads or tails of what's happening. The cpu is being used mostly by mach_msg_trap. I tried drilling down but it seemed like it wasn't related with my code. I still have to learn how to read the results of Instruments. For me it doesn't make any sense that my code is like using 10 samples, and other non-related libraries are taking 2000+ samples.
So anyways, after seeing ngmoco's presentation on how to optimize opengl (also refer to apple's documentation), I thought that I should start optimizing my opengl calls. So I created a wrapper class which batches vertices bound with a texture so I can send all the bullets at one go rather than one by one. But that still didn't improve the performance.
It turned out that while I was coding the collision detection for bullets I had a TODO that I had written some weeks ago saying that I should to optimize it :). Basically I was creating several Vector objects and releasing them for every collision check. That was killing the CPU, but strangely enough the Bullet's update method only had 10 samples marked. Again... I need to learn how to read the results from Instruments. After creating some temporary vectors just once and reusing them, improved the performance.
Have to go try understand the results given by Instruments now... otherwise such problems will come back in my face pretty soon. The worse thing would be that I start optimizing code randomly.
No comments:
Post a Comment