---
description: Performance and Optimization
alwaysApply: false
---

# Performance and Optimization

Guidelines for profiling, memory management, draw call reduction, and platform tuning in Unity.

## Core Principles

- Profile on the target device, not the Editor
- Fix the biggest bottleneck first; don't scatter-shot optimize
- Set explicit frame budgets per platform before development
- Measure before and after every optimization

## Frame Budgets

| Platform | FPS | Budget | Max Draw Calls | Max Tris |
|----------|-----|--------|----------------|----------|
| Mobile (low) | 30 | 33.3ms | <100 | <100K |
| Mobile (high) | 60 | 16.6ms | <200 | <300K |
| Console | 60 | 16.6ms | <2,000 | <2M |
| VR (Quest) | 72 | 13.8ms | <100 | <150K |
| VR (PCVR) | 90 | 11.1ms | <1,000 | <1M |

## GC Allocation Hotspots

| Source | Fix |
|--------|-----|
| String concat in Update | Use StringBuilder once |
| LINQ in hot paths | Manual loops |
| Boxing value types | Generic collections |
| Lambda captures | Cache delegate |
| FindObjectsOfType | Cache results, runtime sets |
| foreach on non-List | for-loop or List<T> |

## Draw Call Reduction

| Technique | How |
|-----------|-----|
| SRP Batcher | Auto with URP/HDRP; batches by shader |
| GPU Instancing | Same mesh + material in one call |
| Static Batching | Combines static meshes at build time |
| Texture Atlasing | Reduces material switches |

## Memory Budgets

| Platform | Budget | Texture Budget |
|----------|--------|----------------|
| Mobile (2GB) | <600MB | <200MB |
| Mobile (4GB) | <1.2GB | <400MB |
| Quest 2/3 | <1.5GB | <512MB |

## Texture Formats

- **iOS/Android (modern)**: ASTC 6x6
- **Android (old)**: ETC2 fallback
- **PC/Console**: BC7

## Platform-Specific Settings

| Platform | Critical Settings |
|----------|------------------|
| iOS | Metal API, ASTC textures, IL2CPP |
| Android | Vulkan primary, GLES 3.2 fallback |
| Quest VR | Single-pass instanced, fixed foveated rendering |
| WebGL | Code stripping, compressed textures, no threads |

## Common Pitfalls

**Editor-Only Profiling**: Editor overhead distorts results. Deploy dev builds to target device, connect Profiler via USB/IP.

**Premature Optimization**: Writing Burst jobs for menu screens. Identify actual bottlenecks via Profiler first.

**GC in Hot Loops**: LINQ, string concat, or `new List<T>()` inside Update/FixedUpdate. Pre-allocate everything.
