When to Use
"slow", "lag", "fps", "memory", "optimize", "profile", "GC", "allocation"
Protocol
1. Measure baseline (FPS, draw calls, GC) → MCP profiler or Unity Profiler
2. Identify hotspot → CPU spike? GC alloc? Draw calls?
3. Fix at source → apply pattern below
4. Measure after → confirm improvement
5. Never optimize without measured issue
Forbidden in Hot Paths (Update/FixedUpdate/LateUpdate)
- ❌
Find(), GetComponent(), Camera.main
- ❌ LINQ, closures, boxing,
string + concat
- ❌
new WaitForSeconds() every frame → cache it
- ❌
CompareTag() via == "string" → use CompareTag()
Fix Patterns
| Problem |
Solution |
| GC spikes |
Cache references in Awake(), use StringBuilder |
| Draw calls |
Enable dynamic/static batching, use atlases |
| Texture memory |
Max 2048 UI, 1024 sprites, compress ASTC |
| Coroutine alloc |
Cache WaitForSeconds, pool coroutines |
| String alloc |
StringBuilder, cached ToString() |
| Event overhead |
OnEnable += / OnDisable -= (prevent leaks) |
MCP Profiler Commands
manage_profiler(action="profiler_start")
manage_profiler(action="get_frame_timing")
manage_profiler(action="get_counters", category="Render")
manage_profiler(action="stats_get")
Context Files (load only if needed)
- Workflow:
.agents/workflows/perf.md
- Persona:
.agents/personas/perf-engineer.md
1---2name: ivx-qv-performance3description: Profile and optimize CPU, memory, GC, and rendering performance for mobile QuizVerse.4---56## When to Use7"slow", "lag", "fps", "memory", "optimize", "profile", "GC", "allocation"89## Protocol10```111. Measure baseline (FPS, draw calls, GC) → MCP profiler or Unity Profiler122. Identify hotspot → CPU spike? GC alloc? Draw calls?133. Fix at source → apply pattern below144. Measure after → confirm improvement155. Never optimize without measured issue16```1718## Forbidden in Hot Paths (Update/FixedUpdate/LateUpdate)19- ❌ `Find()`, `GetComponent()`, `Camera.main`20- ❌ LINQ, closures, boxing, `string +` concat21- ❌ `new WaitForSeconds()` every frame → cache it22- ❌ `CompareTag()` via `== "string"` → use `CompareTag()`2324## Fix Patterns25| Problem | Solution |26|---------|----------|27| GC spikes | Cache references in `Awake()`, use `StringBuilder` |28| Draw calls | Enable dynamic/static batching, use atlases |29| Texture memory | Max 2048 UI, 1024 sprites, compress ASTC |30| Coroutine alloc | Cache `WaitForSeconds`, pool coroutines |31| String alloc | `StringBuilder`, cached `ToString()` |32| Event overhead | `OnEnable +=` / `OnDisable -=` (prevent leaks) |3334## MCP Profiler Commands35```36manage_profiler(action="profiler_start")37manage_profiler(action="get_frame_timing")38manage_profiler(action="get_counters", category="Render")39manage_profiler(action="stats_get")40```4142## Context Files (load only if needed)43- Workflow: `.agents/workflows/perf.md`44- Persona: `.agents/personas/perf-engineer.md`