unity-performance-check
Use before committing code or after major changes to verify performance. Catches expensive operations before they cause frame drops.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Unity Performance Check
Overview
Verify code performance BEFORE it causes problems in production. Frame drops ruin games.
When to Use
- Before committing new code
- After implementing Update/FixedUpdate logic
- When adding new systems
- Before major milestones
- When users report lag
The Quick Check (30 seconds)
Run these searches on changed files:
// RED FLAGS - Fix these immediately:
GetComponent // In Update? Cache it
Find( // In Update? Never do this
FindObjectOfType // Anywhere? Avoid if possible
new List // In Update? Preallocate
new Dictionary // In Update? Preallocate
.ToString() // In Update? Cache or avoid
string + // In Update? StringBuilder
foreach // On non-List? May allocate
The Full Check (5 minutes)
Use the unity-performance-profiler agent:
Task: Launch unity-performance-profiler agent with:
"Analyze [file/folder] for performance issues"
Performance Rules
Update Loop (60fps = 16.6ms budget)
| Operation | Cost | Rule |
|---|---|---|
| GetComponent | ~1ms | Cache in Start |
| Find/FindObjectOfType | ~5-50ms | Never use |
| Instantiate | ~2-10ms | Use object pool |
| new List/Dictionary | ~0.1ms + GC | Preallocate |
| String concat | ~0.5ms + GC | StringBuilder |
| LINQ query | ~1-5ms + GC | Use loops |
| Physics.Raycast | ~0.1ms | Batch or limit |
Memory (GC spikes cause stutters)
| Cause | Solution |
|---|---|
| new in Update | Preallocate collections |
| String operations | Cache strings, use StringBuilder |
| LINQ methods | Convert to explicit loops |
| Boxing (int to object) | Use generics |
| Closures in lambdas | Cache delegates |
| foreach on IEnumerable | Use for loops on arrays/lists |
VeilBreakers-Specific
| System | Performance Concern | Solution |
|---|---|---|
| Combat | Damage calc per frame | Batch damage events |
| Brand lookup | Switch statement | Dictionary lookup |
| Synergy calc | Recalc every frame | Cache on party change |
| UI updates | Rebuild every frame | Dirty flag pattern |
Checklist
Before committing, verify:
- No GetComponent in Update/FixedUpdate
- No Find/FindObjectOfType anywhere
- No allocations in hot paths
- Collections preallocated
- Strings not concatenated in loops
- Events properly unsubscribed
- Object pooling for spawned objects
If Performance is Bad
- Profile first - Don't guess, measure
- Find the hotspot - Usually 1-2 methods
- Fix the algorithm - O(n²) → O(n) > micro-optimizations
- Cache results - Don't recalculate what hasn't changed
- Batch operations - Process multiple items together
- Use jobs/burst - For heavy math (advanced)
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!