Step 3: Fix the problem

Submitted by epreisz on Sun, 02/11/2007 - 08:11.

Resolving the biggest optimization opportunity is ultimate goal of your optimization efforts. Although I’m not going to go into every way to fix an optimization problem now, I do want to cover some general details about fixing slow code.

We will fix issues at all levels of optimization. In general, we want to optimize in the order of system, application, and micro optimizations. The magnitude of work involved in a system level optimization is usually larger than that of an application or micro. The magnitude of an application optimization is usually larger than that of a micro optimization.

Even if you don’t decided to fix any system level issues, you should at least understand the potential optimizations before moving to the application or micro level. When we fix issues at the system level, we are looking for opportunities to utilize our hardware better.

If you determine that you are only using 50% of your CPU, it usually means that your machine supports optimizations for multiple threads. Adding another thread, if done correctly, may significantly increase performance throughout your entire application.

If you determine that you are only using less than 85% to 90% of your GPU, it may be possible to move processing from your CPU to the GPU. Balancing is the term we use to describe the process by which we move processing from an over-utilized resource to an underutilized resource. Moving particle system processing from the CPU to the GPU is one popular example of balancing.

Choosing the correct algorithm is the key to application level optimizations. By first understanding the details at the system level, we can make better decisions about which algorithm to use. It’s important to know that the computational complexity, described by big “O” notation isn’t the only factor in performance. Algorithms with the same big “O” notation may run at different speeds in you application. This is due to their implementations and the resources they consume.

For example, let’s consider two big “O” algorithms of n log n. One is memory efficient and one is computationally expensive, yet they both have the same big “O” notation and on paper, perform the same. If we are already pushing the limits of our performance due to memory issues, a sort with a big “O” of n log n that consumes or fragments memory will not be as fast as a big “O” n log n that is more memory efficient.

Everyone is always searching for the fastest triangle, but they are missing the big picture. The fastest triangle you can render on a graphics card is the triangle you don’t draw at all. Obviously this doesn’t mean that we shouldn’t draw triangles, but what it does mean is that we should make every effort possible to not draw the triangle if it isn’t visible. For example, if a game object, let’s say a zombie, is behind a wall, then don’t draw it. The processing it takes to disregard the zombie as a currently visible object is probably less than the processing it takes to render it.

The same concept is true of other computer operations. The fastest memory we can use is the memory we don’t need to use. The fastest calculation is the calculation we can omit. The fastest pixel we can draw is the one we omit. If we can omit groups of process intensive calculations with one comparison, the resulting performance gains are even more substantial.

Omitting processing on objects is a very common way to enhance performance. Quad trees, oct trees, BSPs are all designed to quickly return objects located near each other. We can traverse these methods to determine quickly if an object has intersected with the camera frustum or a other geometric entities such as rays. LOD, an acronym meaning Level Of Display, is a term we use to describe a system that reduces the amount of processing without changing the experience of the user. A simple example of a LOD is to reduce the number of polygons on an object as it moves farther away from the user. The reduced poly count will not distract the user since the object takes up fewer and fewer pixels on the screen. It is also possible to LOD AI, physics, and processing of animations if they are far away from the user.

Micro level optimizations will help increase the performance of already existing algorithms. Micro level optimizations are a great way to achieve performance without having to change large sections of code. They can be extremely helpful when deadlines are approaching and the time it takes to perform system or application level optimizations simply doesn’t exist. Again, understanding your available resources may greatly effect how you plan to optimize at the micro level.

Throughout these readings we will cover optimizations for the following sections of a gaming application:

  • CPU
  • Memory
  • Threading issues
  • Bus
  • GPU
  • API usage

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Phentermine

Cheap Xanax

Viagra

Buy Phentermine

Ambien

Phentermine

Cheap Ambien

Cheap Phentermine

Buy Phentermine

Phentermine

Rolex Watches

Viagra

Valium

Ambien

Cheap Valium

Ambien

Cheap Valium

Cialis

Xanax

Viagra

Phentermine

Ambien

Buy Phentermine

Xanax

Cheap Phentermine

HGudpCh

OmZPsX HGudpCh

Cialis

Buy Valium

Tramadol

Cialis

Cheap Cigarettes

yidFEWY

MPIJWiaU yidFEWY