Programming‎ > ‎

Optimization

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.

Profile to 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 do that one can use external or internal profiler. A internal profiler is something that one has built into the game and an external is another program that measure it's performance. In the end the profiler gives a measure of the current performance of that area. Common units to measure performance in is seconds (for speed) or bytes (for size). Depending on the scale unit prefixes such as milli or mega is common. When measuring speed one should use the unit seconds and not Frames per second.

 30 Fps: Each frame is ~33ms 60 Fps: Each frame is ~16ms 90 Fps: Each frame is ~11ms 120 Fps. Each frame is ~8ms 144 Fps. Each frame is ~7ms

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

The time it takes for you to compile and link your game is time wasted. It can make you loose focus when waiting for it to complete or try avoiding changes that force a time consuming recompilation.

Profile - Seconds

Optimize

Physical Structure and C++ – Part 1 and Part 2 - 2004


Code Binaries Size
Coding for console are we?


Development Time
No fencing for the design or art team

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. 

Profile - Seconds

Optimize


CPU Speed
Run as fast as possible




F P S


Memory
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.

Profile - Bytes

Optimize


Cache
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.

Profile

Optimize

Content Size
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.

Profile - Bytes
  • Common Limits
    • IOS Over-the-Air App Store limit: 100MB.
    • Google Play APK limit: 50MB
Optimize

  • 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.
Tools


Reference
CppCon 2016: Jason Turner “Practical Performance Practices - 2016
CppCon 2016: Timur Doumler “Want fast C++? Know your hardware!" - 2016
Taming the Jaguar: x86 Optimization at Insomniac Games - 2016
C++ Performance: Common Wisdoms and Common “Wisdoms” - 2016
Stop Misquoting Donald Knuth! - 2015
Understanding Compiler Optimization - Chandler Carruth - Opening Keynote Meeting C++ - 2015
Code Clinic : How to write code the compiler can actually optimize - 2015
Optimizing software in C++ - 2014
Looking For a Good Sort - 2014
The microarchitecture of Intel, AMD and VIA CPUs - 2014
Optimizing subroutines in assembly language - 2014
Vessel: Common Performance Issues - 2013
Don't Help the Compiler - 2013
A Profiling Primer - 2013
Optimisation lessons learned - 2012 Part 1, Part 2 and Part 3.
Visual C++ Performance Pitfalls - 2011
The Windows Heap Is Slow When Launched from the Debugger - 2011
Finding Bottlenecks by Random Breaking - 2011
Hotspots, FLOPS, and uOps: To-The-Metal CPU Optimization - 2011
Optimisation Lesson - 2011 : 1: Profiling , 2: The Pipeline and 3: The Memory Bottleneck.
Optimizations that aren't - 2010
Writing Efficient Game Code for Next-Gen Console Architectures - 2005 









Comments