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. 

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.
Accumulation to Improve Small-Batch Drawing  - 2015
Why (most) High Level Languages are Slow - 2015
Modularity and Drawcall - 2011
EasyProfiler - 2017
Single C file, Realtime CPU/GPU Profiler - 2016

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.

CppCon 2016: Nicolas Fleury “Rainbow Six Siege: Quest for Performance"
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
Optimizing unity renderer - 2015 - Part 1, Part 2 and Part 3
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 1: Profiling - 2011
Optimisation Lesson 2: The Pipeline - 2011
Optimisation Lesson 3: The Memory Bottleneck - 2011
Optimization 101: ordering conditions - 2010
Optimizations that aren't - 2010
Branch Avoidance – A Simple Trick - 2009
Branch Avoidance – A Simple Trick Addendum - 2009
Optimization 101 - 2008

Writing Efficient Game Code for Next-Gen Console Architectures - 2005 
Pablo Zurita's blog: Thoughts on rendering and system programming