In game programming, it is very common to perform a lot of complicated calculations over and over, often many times per frame. There's nothing inherently wrong with that, but sometimes some of those calculations only need to be performed once - e.g. if, given the same parameters, you'd get exactly the same results. In cases like that, you may be served well by caching the result of the calculations rather than performing them again.

With that said, there's a lot more to caching than simply storing the results of performance-intensive calculations - it'd be a mistake (and one I've made frequently) simply to cache everything that looks like it might benefit from being cached.

Read More First article

Often, with C# code (or any language really), it's easy to get away with code that isn't exactly optimized for performance - often without even noticing just how badly it can perform. When developing code to work in a game engine such as Unity, this is especially true. In earlier versions of Unity, for example, the foreach loop is inefficient and leaks garbage, which the garbage collector will then have to spend time cleaning up.

The impact of something like this is relatively minor on the overall performance of your application - but what if the code containing the loop executes multiple times each frame? The unnecessary nanoseconds of execution time consumed by the loop start to add up, especially on devices with less processing power, such as cellphones and tablets.

As such, it's important to learn:

  • When to start optimizing
  • Types of optimization issues
  • How to track down and identify optimization issues
  • How to correct them

Read More First article