Unity CPU Profiling

Ahmed Schrute
Unity Performance Optimization
2 min readOct 25, 2019

Enhancing unity CPU performance

I usually have a routine before I start inspecting the CPU usage tap which is opening all the scripts in the project and do the following:

  1. I go through all the update functions in all scripts and delete any empty auto-generated update function(also delete any empty Start, Awake & OnEnable ).
  2. Delete all the print or Debug.Log calls through all the scripts.
  3. Try as much as I can to replace update function with Fixed Update, Events and Listeners without affecting the app functionality.

Now let's focus on the scripts you wrote by disabling all the taps except the scripts tap, you disable the other tabs by clicking on the small square next to the tab (eg. the green box next to rendering tab).

Before
After

Now, we are ready to inspect the CPU performance by searching for spikes in CPU usage tab.

Once you find a spike, Click on it the spike the game will be paused and select the Player Loop in the Hierarchy.

Selecting Player Loop in the CPU Profiling Hierarchy

For efficiency the calls by the number of calls or % Processing by double-clicking on the column header.

Ordering Functions by number of calls per frame

Now you can see how your scripts are performing and with detailed stats, you can check which script is causing the low fps (You can use deep profiling if you want a more microscopic picture of how your scripts are running).

So you tried to optimize most of the calls but some of the Update calls are essential for the app functionality so how to optimize that.

InvokeRepeating might be useful and also you should have a look at this Blog by Brad Keys.

--

--