Skip to content

Writing for Performance

Fast and snappy games delight users and run well on low end devices. So your reach, user experience, and hence your revenue is tied to performance. It's been proven again and again even for websites.

So investing in learning best practices that lead to simple code and good performance is well worth it.

Algorithms and Data Structures (DSA)

Computer scientists spend their lives inventing faster ways to solve problems. Choosing the right algorithms and data structures can be the difference between your code finishing in a few milliseconds vs a billion years. DSA improves asymptotic complexity.

Our next project contains simple examples to illustrate this. Strive to choose the best algorithms and data structures. Most often these are inbuilt in our language. You just have to recognize and call the appropriate procedures.

Micro-Optimization

We will walk through some techniques of optimizing code like choosing compact bit representations of data, CPU level parallelism, multithreading etc.

Micro optimization increases code complexity. Keep code as simple as possible and use it sparingly when parts of your game are too slow. In my experience, if you use DSA properly and utilize data driven design principles, you won't need micro optimizations.

Counting in Billions

It's quite useful to maintain a mental model of computation limits of modern computers. Modern CPUs run at GHz clock speeds. This translates to approximately a billion simple operations (like addition of numbers) per second.

Odin is fast. If you are coding in other languages there is a slowdown by a constant factor. This works exceptionally well for small pieces of code. Larger codebases written in high level languages tend to be much slower due to death by a thousand cuts.

Language Execution time
C / Odin 1x
Java 2x
Js 6x
Lua / Python 30-60x