Programming‎ > ‎


Premature optimization is the root of bugs that you need to handle for 18 years.

Optimization is the process of improving the performance of the program. The two common things that one try to improve is the speed, so it runs faster, or memory, so it use less of it. Often it is possible to trade one for the other, for example to calculate things in advance so the program do run faster but consume more memory. The process of optimization is made up of the following three steps.

Find the hotspot
First one need to find a area to improve. The best one is the one that has the biggest potential to improve the overall performance. To find this one need to use profilers, memory trackers or other tools. That also gives a measure of the current performance of that area. You need that so you can verify later that your optimization really was worth it.

Optimize it
Do whatever is needed to improve the speed, size or whatever of the hotspot.

Verify improvement
Run the tools (profiler, memory trackers) again to see if the performance has improved. If not try again :).

Build Time
Optimizing this will cut into your fencing practice

Build time is the time for you to compile the code. It is measured is seconds.

Compiler investigations - 2017
Physical Structure and C++ – Part 1 and Part 2 - 2004

Development Time

This is measured is seconds and it is the waste time from the tools you use. It should be as low as possible for the optimal production of the game. One example is if a artist change a texture how long does it take from save in the image software until it is possible to see how the new texture looks in the game. 

Run as fast as possible

When measuring performance one should use the unit seconds and not Frames per second. As times are often small it is most common to use millisecond (ms).
  • Common Limits:
    • 30 Fps: Each frame is ~33ms.
    • 60 Fps: Each frame is ~16ms.
    • 90 Fps: Each frame is ~11ms.
    • 120 Fps. Each frame is ~8ms.

The less memory we use the better

Memory usage are measured in bytes but not all the memory is the same. Some of might only be usable by the GPU or there might be a small amount of memory that is faster.

Access memory in the right order

This is about improving the memory access pattern of the code and in that way also the speed. More information in cache and data oriented design.

Small is good

Many games are now downloaded and patched online and the size of your game can be a download cost for your players. Size optimization is when you try to get the game package as small as possible. It can be the size of the download, storage on the customers computer or the save file. The progress is measured in bytes.
  • Common Limits
    • IOS Over-the-Air App Store limit: 100MB.
    • Google Play APK limit: 50MB
  • Make a pass over all assets and make all of them are still in used. Often many old expired ones get left in the build.
  • Make a tool to list all assets by type and size and verify that they do not use more memory then they need for the place they have in the game.
  • Common assets to look at are textures and sound.