UDN
Search public documentation:

ProfilingBasics
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Performance, Profiling, and Optimization > Basic Profiling and Optimization Techniques

Basic Profiling and Optimization Techniques

Overview


The following sections will help you understand the most useful tools for tracking down performance problems, bottlenecks, and hitches.

Usually the first order of business is determining whether your frame is limited by CPU or GPU performance, and then using the appropriate tools to narrow down the problem.

If the CPU is running slowly there are many commands and debugging tools available to help with this. Sometimes there are simply too many actors and other "moving parts" causing a frame to be slow, or maybe a renegade AI class is firing thousands of ray casts per frame. With some patience you can track these perf issues right down to the individual level actor!

For GPU performance you may need to use PIX to analyze draw events or shader performance, as well as in-game visualization modes and HUD stats. Sometimes these problems can be traced to content layout or lighting properties.

In either case you may be dealing with sustained frame rate problem or a hitch (large frame time spike.) For sustained poor frame rate, single-frame capture tools (such as the TRACE command) and sampling profilers (VTune, etc) may be very useful. For hitches, you'll want to make use of the StatsViewer tool to analyze historical frames using a call graph.

Note that consoles will generally have different performance debugging tools than PC, although many of the Unreal tools will work on multiple platforms.

STAT Commands


When debugging, testing, or profiling games, the ability to quickly and easily see and evaluate meaningful data directly in the game is imperative. Through the use of the STAT console command, Unreal Engine 3 provides the ability to view any number of statsistics about various aspects of the game and engine as data rendered to the screen as a heads-up display.

The Stat Command Descriptions page contains a complete listing of all the stat commands available as well as descriptions of the various metrics shown by each command.

Preparing the Profiling Environment


  1. First, make sure to always have STAT UNIT up while you're running the game
  2. Make sure to turn off any log spam or debug code that will taint performance results
  3. Turn off garbage collection verification because it will contribute to hitching
  4. Disable VSync so you can identify bottlenecks, even on fast frames

STAT UNIT

Use the STAT UNIT command to determine where your frame time bottleneck is. STAT UNIT will toggle an on-screen HUD that displays Frame time, Game thread time, Render thread (Draw) time and GPU time (if possible.) This is an invaluable first step for tracking down performance problems -- you should pretty much always have this turned on.

Also, you an use the STAT FPS command to display frame rate and frame time on the screen.

Turn off garbage collection verification

While working on performance you should always have GC Verification turned off, otherwise you can expect massive hitching in Release builds at least every 30 seconds or so. You can do this using one of the following methods:

  • Pass the -NoVerifyGC command-line argument.

Disabling VSync

For best results you may want to turn off VSync (waits for vertical retrace before presenting frames.) Otherwise the frame time will be padded to the game's refresh rate, which can make it more difficult to get an accurate picture. To turn off VSync:

  • Pass the -NoVSync command-line option to the game.
  • Or, enable the "No VSync" checkbox in the Game tab of Unreal Frontend.

Using STAT SLOW

You can use the STAT SLOW command to help find performance spikes. It can help you narrow down hitches by reporting any cycle stats that run longer than a specific duration in a frame (10 ms by default.) Stats that run slowly will be displayed on the HUD for a little while, making it easier to correlate the spike with game behavior on screen.

To use, enter STAT SLOW in the console with the optional arguments what the threshold is in seconds (so 0.01 for 10 ms) and how long to render the stat once it has spiked once. The default is 10 seconds.

Example: STAT SLOW 0.01 10

This will render all cycle stats that have been > 10 ms in the last 10 seconds.

Tips and Tricks


The following sections contain tips and tricks to keep in mind when profiling for performance issues.

Just Turn It Off

Games normally have a number of features that are exciting to see but are a bit expensive. That is normally fine except when you start doing those expensive things a lot OR when you have a complex scene where those expensive things are causing the scene to be slow. You can spend hours optimizing and getting 20-40% improvements which may not even make the scene fast enough. The other way is to just turn that functionality off!! This is a great strategy for things that may not be noticed when there is lots of carnage occurring or for things that are far in the distance.

Additionally, "just turn it off" is a great technique for doing profiling. Sometimes you need to know if something is going to be worth spending time on optimizing. Just completely turning it off is a great way to say: "If we made this basically free how where are we in terms of our frametime budget".

Example Use Cases:

  • Enemies that are far away from the player don't often need to spawn small blood decals on the ground (e.g. being shot blood effects)
  • Enemies that the LD knows the player will never be able to get reach (e.g. enemies on a cliff that is unreachable) don't need to spawn blood pools or drop weapons
  • Instead of optimizing a complex SkeletalControl, just don't update it when the owner is not visible
  • Instead of simulating cloth when the cloth is not scene, just don't! :-)

Look at a Wall

Quite often code is updating things it really doesn't need to be when they are not visible. Going into a level, turning to face the wall and doing all of the normal profiling that you do is a great way to see if objects are spuriously updating themselves when there is no need.

Of course some things need to update themselves when they are not visible, but a lot of objects can get by without constantly updating.

Spawn N of a Type

Often in the game you will have a number of enemies of the same type attacking you and the game will be slow. Something is slow with that enemy type! The problem is that the rest of the engine is getting in your way for easily being able to see what is slow. A nice way around that is to get a test level and just spawn N of those enemies in that test level and profile that. It will make it really easy to see where the hot spots are!

This is an easy technique to use. Simply do the following:

  • Place N of the problematic object in a test level
  • Profile!