Agent SkillsBesty0728/Unity-Skills › unity-performance

unity-performance

GitHub

提供Unity性能审查建议,识别掉帧、内存分配等红线问题。指导优化Update循环、缓存查找、对象池及避免隐藏的性能陷阱。

SkillsForUnity/unity-skills~/skills/performance/SKILL.md Besty0728/Unity-Skills

Trigger Scenarios

做性能审查 诊断掉帧或卡顿 减少内存分配 规划对象池/优化

Install

npx skills add Besty0728/Unity-Skills --skill unity-performance -g -y
More Options

Non-standard path

npx skills add https://github.com/Besty0728/Unity-Skills/tree/main/SkillsForUnity/unity-skills~/skills/performance -g -y

Use without installing

npx skills use Besty0728/Unity-Skills@unity-performance

指定 Agent (Claude Code)

npx skills add Besty0728/Unity-Skills --skill unity-performance -a claude-code -g -y

安装 repo 全部 skill

npx skills add Besty0728/Unity-Skills --all -g -y

预览 repo 内 skill

npx skills add Besty0728/Unity-Skills --list

SKILL.md

Frontmatter
{
    "name": "unity-performance",
    "description": "Advise on Unity performance red flags. 为 Unity 性能红线提供建议。"
}

Triggers

  • Reviewing performance
  • Diagnosing frame drops
  • Reducing allocations
  • Planning pooling/optimization
  • 做性能审查、诊断掉帧或卡顿、减少内存分配、规划对象池/优化

Unity Performance Red Flags

Use this skill for a high-signal review of likely Unity performance issues. Focus on red flags, not speculative micro-optimizations.

Check For

  • Too many unrelated Update / LateUpdate / FixedUpdate loops
  • Repeated Find, GetComponent, Camera.main, or tag lookups in hot paths
  • Frequent Instantiate / Destroy suitable for pooling
  • Avoidable per-frame allocations:
    • LINQ
    • string formatting
    • closures
    • boxing
  • Reflection in runtime hot paths
  • Expensive editor-only helpers leaking into runtime code
  • Physics, animation, or UI updates happening at the wrong cadence

Hidden Costs: Possibility ≠ Actuality

Three counter-intuitive traps where what seems "free" is actually expensive. Each cost is paid for possibility of work, not for work actually performed — which is why profilers rarely catch them directly.

Write permission costs, even without writing

A component whose Update can mutate transform.position pays the cost whether the branch runs or not: dirty-flag and serialization systems treat write permission as a reason to poll every frame. Similarly, a [SerializeField] field that is never modified at runtime still sits on the serialization path. The fix is to remove the permission, not tighten the branch — split the rarely-needed writer into its own component and AddComponent only when needed. Source: NetcodeSamples/HelloNetcode/2_Intermediate/07_Optimization/Optimization.md — "a system with the possibility of writing to a component, regardless of whether it writes to it or not, will always have to be serialized".

Sequential seeds produce correlated random streams

Seeding N RNG instances with baseSeed + i gives N similar streams — patrol paths line up, spawn jitter clumps, loot rolls cluster. Hash the index before seeding:

// Wrong — N correlated streams
for (int i = 0; i < N; i++) rngs[i] = new System.Random(baseSeed + i);

// Correct — hash decorrelates adjacent seeds
for (int i = 0; i < N; i++)
    rngs[i] = new System.Random((int)((uint)baseSeed * 2654435761u ^ (uint)i));

Unity.Mathematics.Random.CreateFromIndex(i) applies this internally and is preferred when the math package is available. Source: Dots101/Entities101/Assets/HelloCube/3. Prefabs/SpawnSystem.cs:37-39 and its comment.

Logging fires in release builds by default

Debug.Log is not stripped in Player builds; only methods marked [Conditional("UNITY_EDITOR")] (such as Debug.DrawLine) have their arguments elided at the call site. That means a log line with interpolation or helper calls runs every frame in shipped games:

// Wrong — GetPlayerInfo() and string interpolation execute in release
Debug.Log($"Player {GetPlayerInfo()} at {Time.time}");

// Better — guard the whole expression
if (Debug.isDebugBuild) Debug.Log($"Player {GetPlayerInfo()} at {Time.time}");

The same principle as the "possibility write" rule above — the runtime pays for the possibility of work, not only for the work.

Output Format

  • Confirmed red flags
  • Likely red flags
  • Changes worth doing now
  • Changes not worth doing now
  • Expected gain category: clarity / frame time / GC / scalability

Guardrails

Mode: Documentation only — no REST skills to gate; load freely under any operating mode (Approval / Auto / Bypass).

  • Do not recommend large refactors without a meaningful hotspot.
  • Do not replace simple code with unreadable “optimized” code unless the hot path is real.

Version History

  • 25d511e Current 2026-08-13 09:14

    压缩75个SKILL.md description至约5,191字符,并将路由说明移入Triggers章节。

  • ec9f870 2026-07-05 14:40

Same Skill Collection

SkillsForUnity/unity-skills~/skills/addressables-design/SKILL.md
SkillsForUnity/unity-skills~/skills/adr/SKILL.md
SkillsForUnity/unity-skills~/skills/animator/SKILL.md
SkillsForUnity/unity-skills~/skills/architecture/SKILL.md
SkillsForUnity/unity-skills~/skills/asmdef/SKILL.md
SkillsForUnity/unity-skills~/skills/asset/SKILL.md
SkillsForUnity/unity-skills~/skills/async/SKILL.md
SkillsForUnity/unity-skills~/skills/batch/SKILL.md
SkillsForUnity/unity-skills~/skills/behavior/SKILL.md
SkillsForUnity/unity-skills~/skills/blueprints/SKILL.md
SkillsForUnity/unity-skills~/skills/bookmark/SKILL.md
SkillsForUnity/unity-skills~/skills/camera/SKILL.md
SkillsForUnity/unity-skills~/skills/cinemachine/SKILL.md
SkillsForUnity/unity-skills~/skills/cleaner/SKILL.md
SkillsForUnity/unity-skills~/skills/console/SKILL.md
SkillsForUnity/unity-skills~/skills/debug/SKILL.md
SkillsForUnity/unity-skills~/skills/decal/SKILL.md
SkillsForUnity/unity-skills~/skills/dotween-design/SKILL.md
SkillsForUnity/unity-skills~/skills/dotween/SKILL.md
SkillsForUnity/unity-skills~/skills/editor/SKILL.md
SkillsForUnity/unity-skills~/skills/event/SKILL.md
SkillsForUnity/unity-skills~/skills/gameobject/SKILL.md
SkillsForUnity/unity-skills~/skills/graphics/SKILL.md
SkillsForUnity/unity-skills~/skills/history/SKILL.md
SkillsForUnity/unity-skills~/skills/hybridclr/SKILL.md
SkillsForUnity/unity-skills~/skills/inspector/SKILL.md
SkillsForUnity/unity-skills~/skills/light/SKILL.md
SkillsForUnity/unity-skills~/skills/material/SKILL.md
SkillsForUnity/unity-skills~/skills/navmesh/SKILL.md
SkillsForUnity/unity-skills~/skills/netcode-design/SKILL.md
SkillsForUnity/unity-skills~/skills/netcode/SKILL.md
SkillsForUnity/unity-skills~/skills/package/SKILL.md
SkillsForUnity/unity-skills~/skills/patterns/SKILL.md
SkillsForUnity/unity-skills~/skills/perception/SKILL.md
SkillsForUnity/unity-skills~/skills/physics/SKILL.md
SkillsForUnity/unity-skills~/skills/postprocess/SKILL.md
SkillsForUnity/unity-skills~/skills/primetween-design/SKILL.md
SkillsForUnity/unity-skills~/skills/primetween/SKILL.md
SkillsForUnity/unity-skills~/skills/probuilder/SKILL.md
SkillsForUnity/unity-skills~/skills/profiler/SKILL.md
SkillsForUnity/unity-skills~/skills/project-scout/SKILL.md
SkillsForUnity/unity-skills~/skills/project/SKILL.md
SkillsForUnity/unity-skills~/skills/sample/SKILL.md
SkillsForUnity/unity-skills~/skills/scene-contracts/SKILL.md
SkillsForUnity/unity-skills~/skills/script-roles/SKILL.md
SkillsForUnity/unity-skills~/skills/script/SKILL.md
SkillsForUnity/unity-skills~/skills/scriptableobject/SKILL.md
SkillsForUnity/unity-skills~/skills/scriptdesign/SKILL.md
SkillsForUnity/unity-skills~/skills/shader/SKILL.md

Metadata

Files
0
Version
25d511e
Hash
42daaf61
Indexed
2026-07-05 14:40

inicio - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-16 21:21
浙ICP备14020137号-1 $mapa de visitantes$