This document is about: QUANTUM 2
SWITCH TO

Profiling

Introduction

Profiling in general is a good tool to find the relative performance between parts of the code and enable developers to drill down on hotspots. But it's not useful to find absolute performance measurements because profiling tools, especially Unity's, impact the performance with their overhead.

The recommended performance analysis path is:

  1. Measure simulation times, rendering times, etc using a Quantum Release build (quantum solution) and an IL2CPP Unity build only the Quantum Graph Profiler attached to give overall numbers over time;
  2. Make sure to either set either zero or a high value into DeterministicConfig.ChecksumInterval as frequent checksums have an impact on performance;
  3. Then, with the rough idea where to look (is it the simulation, is it rendering, etc), follow up with a profiling session using the Unity Profiler or Quantum Task Profiler.

Keep in mind that a Quantum debug build can be 5x slower than a release build. As well as that a debug+mono build can be 10x slower that a release+il2cpp build.

Unity Profiler

Quantum performance stats are integrated into the Unity Profiler and are started by default inside the QuantumRunner script.

C#

Quantum.Profiling.HostProfiler.Init(..)

You can add custom sections in your Quantum simulation code by this know Unity Profiler pattern:

C#

HostProfiler.Start("Foo");
{
  HostProfiler.Start("Bar1");
  // do work
  HostProfiler.End();

  HostProfiler.Start("Bar2");
  // do work
  HostProfiler.End();
}
HostProfiler.End();

With the most current Quantum SDK versions (2.1) Quantum also supplies data for the Timeline profiler in Unity. Quantum only provides profiling data in Debug configuration.

Quantum Task Profiler

The Quantum Task Profiler is a custom and stand-alone graphical performance profiler for Unity similar to the Unity Timeline profiler. It only provides data when the quantum solution is compiled in Debug or in ReleaseProfiler configuration (the latter being added in Quantum 2.1). Similar to the Unity Profiler an app running on a remote device connects to the Unity Editor via UDP inside the same local network.

Quantum Task Profiler
Quantum Task Profiler

Remote Profiling

It is possible to remotely hook into the Quantum Task Profiler to build running on the same network as the editor (UDP Port 30000). To enable the feature, simply toggle the Remote Profiler checkbox at the bottom of the QuantumEditorSettings asset. Close and reopen the Task Profiler View afterwards.

Profiling Graphs
Toggle for the Remote Profiler in the QuantumEditorSettings

Quantum Graph Profiler

The Quantum Graph provider is an extra tool that can be integrate into an app to visually analyze performance and network statistics.

Please download the version for your Unity Editor:

Unity Version Release Date Download
Unity 2018.4 Jan 30, 2020 QuantumProfilers_Unity2018_20230414
Unity 2019.4+ Jan 21, 2022 QuantumProfilers_20230414

Real-Time Profiling

These runtime graphs help tracking the overall performance of the game and the Quantum simulation under various network conditions. The graphs and their values are based on the Unity update rate where each value equals the accumulated time/count/etc... in a single Unity frame.

The profiler offers graphs for:

  • Engine Delta Time: equals Time.unscaledDeltaTime between Unity frames. Sometimes Engine Delta Time may not reflect the target FPS, to fix this set QualitySettings.vSyncCount = 0;
  • Frame Time: all scripts logic including Unity internal and rendering, but excluding the wait for end of frame;
  • User Scripts Time: the time to run FixedUpdate() + Update() + LateUpdate();
  • Render Time: equals time from last LateUpdate() until the end of render;
  • Simulation Time: equals QuantumRunner.Default.Game.Session.Stats.UpdateTime;
  • Predicted Frames: the amount of predicted Quantum frames simulated in a Unity frame equals QuantumRunner.Default.Game.Session.PredictedFrames;
  • Verified Frames: the amount of verified Quantum frames simulated in a Unity frame;
  • Network Activity: the time since the last data transmission from the server;
  • Ping: network peer round trip time (RTT);
  • Markers: up to 8 custom boolean can track values using markers. Each marker is represented by unique color; by default Red = input replaced by server and Orange = checksum calculated.
Profiling Graphs
Real-Time Profiling Graphs

A Note on Markers

For better legibility, the markers graph is running 2x faster than the others. This can be adjusted via the Samples property on the Profilers prefab.

Multiple instances of MarkersProfiler are supported:

  1. Get an instance by name MarkersProfiler profiler = MarkersProfiler.Get(GAMEOBJECT_NAME);
  2. Call profiler.SetMarker(INDEX);

Other tools

The real-time profiling tool also contains other (more basic) tools for:

  • changing target FPS (Application.targetFrameRate); and,
  • to simulate network conditions (lag, jitter, loss).

These are useful to quickly simulate different rendering speeds and bad networks. The effects can be seen immediately in graphs (predicted frames, simulation time, ...).

N.B.: When simulating network loss, set values carefully. Use 1-3% to simulate loss on network and higher values to simulate local loss (e.g. bad connection to router behind 3 walls).

Back to top