You are ready to show your game in its early version, you have implemented all the features you have planned for this release and has even built a release version. It was a little bit slow in debug, but you hope it’ll go much faster in release. So you build a release and try your own game as it is before you show it to others. So you play for a little while and it goes slower, slower and slower. In the end you can’t really enjoy the game as it’s just “hanging”. If it’s true for you then you have performance issues.
Discovering performance issues.
The first thing is to be aware that your game will probably have performance issues and all you need is to discover them before your players do.
1. Play the game long enough and watch for how much memory your game uses (For Windows you can simply use Process Explorer to do that). If it grows all the time and passes all possible values, then you have a memory leak.
2. Start the game and watch for how much memory your game uses at start point. Play for some time and then return to the start point. Ideally the memory used should be the same as you measured at start time.
Fixing performance issues.
Well, there is a saying “Finding a problem is a job half done”. It can or cannot be true for video games. Sometimes even if you know that there is an issue you can’t really find where it is. Here comes the most difficult job.
1. You can look at your code and try to think where are there the most possible places for memory leaks to be found. Look especially at:
– classes with many instances (grid chunks, scene objects, trees, bushes and so on)
– arrays, lists, maps and other collections. Did you remember to clear the lists and clear the arrays after they were used?
Look here for more examples: C++MemoryCorruptionAndMemoryLeaks
2. Use a memory checker to monitor your game for memory leaks. This approach would be great if there were tools that give you a possibility to play without it all hanging. Video games are usually pretty heavy by themselves so if you inject more processes that will have to monitor everything you do, then it becomes really really slow.
3. Use a profiler to find the hotspots where the CPU is using most of the time. A good profiler will tell you where the application is struggling with your code.
And as always, use const references wherever possible.