Unity CPU Profiling

Unity CPU Profiling

Enhancing unity CPU performance

No alt text provided for this image


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 StartAwake & 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

No alt text provided for this image

After

No alt text provided for this image

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.

No alt text provided for this image

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

No alt text provided for this image

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.

To view or add a comment, sign in

More articles by Ahmed Schrute

  • Genetic Evolution (Behavioral Traits) Simulation using Unity3D

    This is a simulation of Genetic Evolution with a focus on Behavioral traits passed between generation, In this…

  • Vertex Fragment Shader Structure

    This article is a continuum of shader coding articles using Shader lab in Unity, I highly recommend you visit my two…

  • Rendering Queues in Unity

    A lot of times, we need to render certain objects(Player, Gem …etc) to the front even there is an object overlaying our…

  • Normal Mapping

    If you have read the Lighting in Unity 1 and Lighting in Unity2, you have seen how important normal vectors are for…

    2 Comments
  • Light in Unity 2

    Intro to Blinn Phong Lighting model In the previous article, We have been through Lambert Lighting Model and how it…

  • Light in Unity 1

    Introduction to Lighting in Unity and Lambert Lighting Lighting in Computer Graphics is all about calculating the Pixel…

  • Shader Variables Data Types in Unity

    Why we use different variable types when writing shaders? Shader code is for every pixel(or vertex), therefor efficient…

  • Understanding Mesh Anatomy in Unity

    In order to shade a model we need to understand its geometric structure Let’s take a cube as an example of a mesh model…

  • Rendering Pipeline In Unity

    Introduction to Rendering Pipeline in Unity Rendering Rendering is the process of drawing a scene on the computer…

Others also viewed

Explore content categories