【Unity】Unity Profiler Introduction: Discovering and Optimizing Performance Bottlenecks

Created: 2025-12-07

Game running slow or stuttering? The Profiler is essential for identifying causes. Learn to visually analyze CPU usage, memory allocation, and rendering load to discover and optimize performance bottlenecks.

Overview

In game development, "creating a fun game" is equally important as "creating a game that runs smoothly." Frame rate drops (stuttering) and crashes from excessive memory usage severely damage player experience. To solve performance issues, you must first accurately identify "what is slow, where, and why." Unity's built-in Profiler is the most powerful tool for this.

The Profiler collects various performance data during gameplay—CPU usage, memory allocation, rendering, physics—on a per-frame basis, displaying them as graphs and detailed lists. This enables developers to identify bottlenecks based on data rather than guesswork, allowing targeted optimization.

This article covers basic Profiler usage and how to read key modules for discovering common performance problems.

Basic Profiler Usage

  1. Open Profiler Window: Select Window > Analysis > Profiler from the menu.

  2. Select Profiling Target: Use the Playmode dropdown at the top to select what to profile. Editor profiles games running in Unity Editor; selecting Enter IP or connected device names profiles development builds running on actual devices (PC, mobile, console). For accurate performance measurement, always profile on target hardware.

  3. Start Recording: Confirm Record button is on and play the game. Module graphs begin updating in real-time.

  4. Select and Analyze Frames: Click frames with spikes (prominent peaks) or particularly heavy processing on the graph. Detailed processing information for that frame appears at the bottom of the window. Drill down to see specific information like how many milliseconds each method call took.

Key Profiler Modules

The left side of the Profiler window lists modules for different analysis needs.

CPU Usage

The most commonly used module. Shows what the CPU spent time on each frame.

  • Timeline View: Shows processing for each thread (Main Thread, Render Thread, etc.) chronologically. Helps grasp which processing is extending total frame time.
  • Hierarchy View: Displays all method calls within a frame hierarchically. Sort by Time ms or Self ms (that method's own processing time) to identify the most time-consuming processes.
    • Common Bottlenecks: Heavy processing running every frame in Update(), calling GetComponent() in loops, complex physics, inefficient AI logic, etc.

GPU Usage

Shows what the GPU spent time on for rendering. Useful when GPU is the bottleneck (GPU Bound). (Available only on some platforms)

Rendering

Shows what draw commands the CPU sent to the GPU.

  • Batches: Draw call count. Too many increase CPU load. Optimize for static/dynamic batching by sharing materials.
  • SetPass Calls: Shader/material switch count. Also causes CPU load.
  • Triangles / Vertices: Polygon/vertex count displayed in scene. Too many increase GPU load.

Memory

Shows how much memory the game allocates and uses.

  • Simple View: See overview like Total Reserved Memory and Unity (memory used by Unity engine).
  • Detailed View: Press Take Sample to capture a snapshot of all assets and objects in memory at that moment. Very powerful for identifying which textures, meshes, or audio clips are consuming memory. Common causes: textures with excessive resolution or improper compression settings.

GC (Garbage Collection)

In CPU Usage Profiler, you may see GC.Collect appearing as large spikes. This means Garbage Collection (GC) occurred. GC is a convenient mechanism that automatically cleans up unused memory, but game execution temporarily pauses (stutters) during processing, causing player-perceptible stuttering.

The main cause of GC is unnecessary memory allocation in Update(). For example:

  • String concatenation (string a = "hello" + "world";)
  • Class instantiation with new keyword
  • New array creation (new Vector3[10])

Doing these every frame generates lots of small garbage, causing frequent GC. Focus on the GC Alloc column, identify processing that allocates memory every frame, and reduce it as much as possible—this is key to suppressing GC spikes.

Summary

The Profiler is like a "stethoscope" or "X-ray" for performance optimization.

  • Don't optimize by guesswork. Always measure with Profiler and identify bottlenecks based on data.
  • For accurate measurement, profile on actual devices whenever possible.
  • Use CPU Usage module to identify time-consuming methods.
  • Use Rendering module to check batch count and polygon count.
  • Use Memory module to identify memory-consuming assets.
  • Focus on GC Alloc and reduce unnecessary memory allocations to prevent GC spikes.

Performance optimization is painstaking work, but mastering the Profiler lets you efficiently discover problems and deliver comfortable gaming experiences to players.