[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CS4QH0WFVG5A8SV3G4T8FE":3,"skill-same:01M7CS4QH0WFVG5A8SV3G4T8FE":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":27,"commitSha":28,"skillDirectory":29,"forksCount":30,"repositoryHtmlUrl":31,"repositoryHomepageUrl":32,"ownerHtmlUrl":33,"ownerBlogUrl":6,"ownerDescription":34,"updatedAt":35,"install":36,"resources":49},"01M7CS4QH0WFVG5A8SV3G4T8FE","unity-performance-and-gc",null,"Use when touching Unity per-frame code, spawning, physics queries, UI updates or rendering setup - profiling with numbers, zero-GC hot paths (caching, NonAlloc queries, no LINQ\u002Fclosures\u002Fboxing, TMP SetText), ObjectPool, allocation tests, Burst\u002FJobs for bulk math, and rendering\u002Fphysics settings that cost frames.","makifbaysal\u002Ftasktrooper","makifbaysal","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F25031940?v=4","01M7CRG3ZCSYZSSEVDMW3DEYC8","Mehmet Akif Baysal","01M7CRG401FJ8YAXH5ER730XYV",122,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fgame-developer\u002Fskills\u002Funity-performance-and-gc\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: unity-performance-and-gc\ncategory: performance\ndescription: Use when touching Unity per-frame code, spawning, physics queries, UI updates or rendering setup - profiling with numbers, zero-GC hot paths (caching, NonAlloc queries, no LINQ\u002Fclosures\u002Fboxing, TMP SetText), ObjectPool, allocation tests, Burst\u002FJobs for bulk math, and rendering\u002Fphysics settings that cost frames.\ntech_stack: Unity\nsource: informed by the Unity 6 Manual (Profiler, memory and GC, Jobs, Burst, ObjectPool, physics queries) and Unity's optimisation guides; own wording\n---\n# Unity Performance and GC\n\n## Overview\n\nUnity's managed heap is garbage-collected; every allocation in `Update` is a future GC spike, and the incremental collector only spreads the pain. Most frame drops in Unity projects come from a short list: allocations per frame, per-frame lookups, unpooled spawning, physics queries that allocate, UI rebuilds, and draw calls. Find which one with the Profiler, fix it, and prove the fix with numbers (game-performance-budget).\n\n**Core principle:** Zero managed allocations per frame in gameplay, measured — not assumed — with the Profiler's GC Alloc column or an allocation test.\n\n## Profile first\n\n- Profiler: CPU Usage (Hierarchy, sort by Time ms and GC Alloc), Rendering, Physics, Memory modules. Profile a Development Build with Autoconnect; the Editor adds overhead.\n- Deep Profile only to locate a call, never for timing.\n- Profile Analyzer compares a before and an after capture; Memory Profiler finds leaks across scene loads.\n- Mark your own code: `static readonly ProfilerMarker s_Marker = new(\"Enemy.Think\"); using (s_Marker.Auto()) { ... }`.\n\n## The allocation list\n\n```csharp\n\u002F\u002F ❌ allocates or searches every frame\nvoid Update() {\n    var enemies = FindObjectsByType\u003CEnemy>(FindObjectsSortMode.None);       \u002F\u002F array + scene search\n    var close = enemies.Where(e => (e.transform.position - transform.position).sqrMagnitude \u003C r2).ToList(); \u002F\u002F LINQ + closure\n    hpText.text = \"HP: \" + hp;                                              \u002F\u002F new string every frame\n    if (other.tag == \"Enemy\") { }                                           \u002F\u002F allocates the tag string\n    var hits = Physics.OverlapSphere(transform.position, 5f);              \u002F\u002F new array per call\n    StartCoroutine(Flash(new WaitForSeconds(0.1f)));                        \u002F\u002F allocation per call\n}\n\n\u002F\u002F ✅ cached, reused, non-allocating\nreadonly Collider[] _hits = new Collider[32];\nstatic readonly WaitForSeconds FlashDelay = new(0.1f);\nint _shownHp = -1;\n\nvoid Update() {\n    int count = Physics.OverlapSphereNonAlloc(transform.position, 5f, _hits, enemyMask);\n    for (int i = 0; i \u003C count; i++) { \u002F* use _hits[i] *\u002F }\n    if (hp != _shownHp) { _shownHp = hp; hpText.SetText(\"HP: {0}\", hp); }   \u002F\u002F TextMeshPro, no string alloc\n    if (other.CompareTag(\"Enemy\")) { }\n}\n```\n\nMore of the same:\n- 3D queries: `RaycastNonAlloc`, `SphereCastNonAlloc`, `OverlapBoxNonAlloc`. 2D: the overloads taking a `ContactFilter2D` and a reused `List\u003CT>`\u002Farray (the 2D `*NonAlloc` methods are obsolete).\n- `GetComponentsInChildren(list)` overloads that fill a reused list.\n- `Animator.StringToHash`, `Shader.PropertyToID`, cached `WaitForSeconds`\u002F`WaitForFixedUpdate`.\n- `foreach` over `List\u003CT>` and arrays is fine; over an `IEnumerable\u003CT>` interface it boxes the enumerator.\n- No capturing lambdas, `string.Format`\u002Finterpolation, `params` arrays or boxing (struct → `object`\u002Finterface) in hot paths.\n- `Debug.Log` in a hot path allocates and stalls — strip it from builds (`[Conditional(\"UNITY_EDITOR\")]` wrapper) or remove it.\n- `Camera.main` is cheaper than it was but is still a lookup — cache it.\n\n## Pool what you spawn\n\n```csharp\nusing UnityEngine.Pool;\n\npublic sealed class BulletSpawner : MonoBehaviour {\n    [SerializeField] Bullet prefab;\n    ObjectPool\u003CBullet> _pool;\n\n    void Awake() => _pool = new ObjectPool\u003CBullet>(\n        createFunc: () => { var b = Instantiate(prefab); b.Init(release: x => _pool.Release(x)); return b; },\n        actionOnGet: b => b.gameObject.SetActive(true),\n        actionOnRelease: b => b.gameObject.SetActive(false),\n        actionOnDestroy: b => Destroy(b.gameObject),\n        collectionCheck: false, defaultCapacity: 64, maxSize: 256);\n\n    public void Fire(Vector3 pos, Vector3 dir) { var b = _pool.Get(); b.Launch(pos, dir); }\n}\n```\n\nPre-warm at load (get and release `defaultCapacity` instances) so the first fight does not instantiate. A pooled object resets all its state in `actionOnGet`\u002F`Launch`, not in `Start`.\n\n## Prove zero allocations\n\n```csharp\nusing Is = UnityEngine.TestTools.Constraints.Is;\n\n[Test] public void Tick_SteadyState_DoesNotAllocate() {\n    var sim = TestSim.WithEnemies(100);\n    sim.Tick(0.016f);                                    \u002F\u002F warm-up: first call may JIT\u002Finitialise\n    Assert.That(() => sim.Tick(0.016f), Is.Not.AllocatingGCMemory());\n}\n```\n\n## Burst and Jobs for bulk work\n\nFor the same math over hundreds or thousands of items (flocking, projectiles, terrain), a Burst-compiled job on native containers:\n\n```csharp\n[BurstCompile]\nstruct MoveJob : IJobParallelFor {\n    public NativeArray\u003Cfloat3> Positions;\n    [ReadOnly] public NativeArray\u003Cfloat3> Velocities;\n    public float Dt;\n    public void Execute(int i) => Positions[i] += Velocities[i] * Dt;\n}\n\u002F\u002F schedule: var h = new MoveJob { ... }.Schedule(count, 64); later h.Complete();\n```\n\n- Native containers are disposed (`Allocator.Persistent` in `OnDestroy`; `TempJob` within four frames; `Temp` within the frame).\n- Complete handles before reading results; schedule early, complete late.\n- At entity scale, consider DOTS (unity-dots-ecs) — only if the project already uses it or the task decides it.\n\n## Rendering and physics settings that cost frames\n\n- URP\u002FHDRP: keep the SRP Batcher compatible (shaders with CBUFFERs; avoid per-renderer `MaterialPropertyBlock` where it breaks batching); GPU instancing for repeated meshes; static batching for static scenery; Sprite Atlases for 2D.\n- UI: split static and frequently changing elements into separate Canvases; turn off Raycast Target on non-interactive graphics; never animate layout groups every frame.\n- Overdraw: transparent particles and full-screen effects, especially on mobile; LODs and occlusion culling for 3D.\n- Physics: the layer collision matrix trims pair checks; primitive colliders over mesh colliders on moving bodies; `Physics.autoSyncTransforms` off; tune `Time.fixedDeltaTime` deliberately.\n- Mobile: set `Application.targetFrameRate` explicitly; watch thermal throttling over minutes, not seconds.\n\n## Common Mistakes\n\n- Optimising from intuition without a Profiler capture.\n- `Instantiate`\u002F`Destroy` for bullets, hit effects and damage numbers.\n- Updating TextMeshPro text every frame with string concatenation.\n- Allocation test without a warm-up call, failing on first-call initialisation.\n- Leaking `NativeArray`s (the leak detection warning in the console is a real bug).\n\n## Red Flags\n\n- `GC.Alloc` above zero in a gameplay `Update` in the Profiler.\n- LINQ, `FindObjectsByType`, `GetComponent` or `new` inside `Update`\u002F`FixedUpdate`.\n- A performance claim in the closing message without before\u002Fafter numbers.\n","# Unity Performance and GC\n\n## Overview\n\nUnity's managed heap is garbage-collected; every allocation in `Update` is a future GC spike, and the incremental collector only spreads the pain. Most frame drops in Unity projects come from a short list: allocations per frame, per-frame lookups, unpooled spawning, physics queries that allocate, UI rebuilds, and draw calls. Find which one with the Profiler, fix it, and prove the fix with numbers (game-performance-budget).\n\n**Core principle:** Zero managed allocations per frame in gameplay, measured — not assumed — with the Profiler's GC Alloc column or an allocation test.\n\n## Profile first\n\n- Profiler: CPU Usage (Hierarchy, sort by Time ms and GC Alloc), Rendering, Physics, Memory modules. Profile a Development Build with Autoconnect; the Editor adds overhead.\n- Deep Profile only to locate a call, never for timing.\n- Profile Analyzer compares a before and an after capture; Memory Profiler finds leaks across scene loads.\n- Mark your own code: `static readonly ProfilerMarker s_Marker = new(\"Enemy.Think\"); using (s_Marker.Auto()) { ... }`.\n\n## The allocation list\n\n```csharp\n\u002F\u002F ❌ allocates or searches every frame\nvoid Update() {\n    var enemies = FindObjectsByType\u003CEnemy>(FindObjectsSortMode.None);       \u002F\u002F array + scene search\n    var close = enemies.Where(e => (e.transform.position - transform.position).sqrMagnitude \u003C r2).ToList(); \u002F\u002F LINQ + closure\n    hpText.text = \"HP: \" + hp;                                              \u002F\u002F new string every frame\n    if (other.tag == \"Enemy\") { }                                           \u002F\u002F allocates the tag string\n    var hits = Physics.OverlapSphere(transform.position, 5f);              \u002F\u002F new array per call\n    StartCoroutine(Flash(new WaitForSeconds(0.1f)));                        \u002F\u002F allocation per call\n}\n\n\u002F\u002F ✅ cached, reused, non-allocating\nreadonly Collider[] _hits = new Collider[32];\nstatic readonly WaitForSeconds FlashDelay = new(0.1f);\nint _shownHp = -1;\n\nvoid Update() {\n    int count = Physics.OverlapSphereNonAlloc(transform.position, 5f, _hits, enemyMask);\n    for (int i = 0; i \u003C count; i++) { \u002F* use _hits[i] *\u002F }\n    if (hp != _shownHp) { _shownHp = hp; hpText.SetText(\"HP: {0}\", hp); }   \u002F\u002F TextMeshPro, no string alloc\n    if (other.CompareTag(\"Enemy\")) { }\n}\n```\n\nMore of the same:\n- 3D queries: `RaycastNonAlloc`, `SphereCastNonAlloc`, `OverlapBoxNonAlloc`. 2D: the overloads taking a `ContactFilter2D` and a reused `List\u003CT>`\u002Farray (the 2D `*NonAlloc` methods are obsolete).\n- `GetComponentsInChildren(list)` overloads that fill a reused list.\n- `Animator.StringToHash`, `Shader.PropertyToID`, cached `WaitForSeconds`\u002F`WaitForFixedUpdate`.\n- `foreach` over `List\u003CT>` and arrays is fine; over an `IEnumerable\u003CT>` interface it boxes the enumerator.\n- No capturing lambdas, `string.Format`\u002Finterpolation, `params` arrays or boxing (struct → `object`\u002Finterface) in hot paths.\n- `Debug.Log` in a hot path allocates and stalls — strip it from builds (`[Conditional(\"UNITY_EDITOR\")]` wrapper) or remove it.\n- `Camera.main` is cheaper than it was but is still a lookup — cache it.\n\n## Pool what you spawn\n\n```csharp\nusing UnityEngine.Pool;\n\npublic sealed class BulletSpawner : MonoBehaviour {\n    [SerializeField] Bullet prefab;\n    ObjectPool\u003CBullet> _pool;\n\n    void Awake() => _pool = new ObjectPool\u003CBullet>(\n        createFunc: () => { var b = Instantiate(prefab); b.Init(release: x => _pool.Release(x)); return b; },\n        actionOnGet: b => b.gameObject.SetActive(true),\n        actionOnRelease: b => b.gameObject.SetActive(false),\n        actionOnDestroy: b => Destroy(b.gameObject),\n        collectionCheck: false, defaultCapacity: 64, maxSize: 256);\n\n    public void Fire(Vector3 pos, Vector3 dir) { var b = _pool.Get(); b.Launch(pos, dir); }\n}\n```\n\nPre-warm at load (get and release `defaultCapacity` instances) so the first fight does not instantiate. A pooled object resets all its state in `actionOnGet`\u002F`Launch`, not in `Start`.\n\n## Prove zero allocations\n\n```csharp\nusing Is = UnityEngine.TestTools.Constraints.Is;\n\n[Test] public void Tick_SteadyState_DoesNotAllocate() {\n    var sim = TestSim.WithEnemies(100);\n    sim.Tick(0.016f);                                    \u002F\u002F warm-up: first call may JIT\u002Finitialise\n    Assert.That(() => sim.Tick(0.016f), Is.Not.AllocatingGCMemory());\n}\n```\n\n## Burst and Jobs for bulk work\n\nFor the same math over hundreds or thousands of items (flocking, projectiles, terrain), a Burst-compiled job on native containers:\n\n```csharp\n[BurstCompile]\nstruct MoveJob : IJobParallelFor {\n    public NativeArray\u003Cfloat3> Positions;\n    [ReadOnly] public NativeArray\u003Cfloat3> Velocities;\n    public float Dt;\n    public void Execute(int i) => Positions[i] += Velocities[i] * Dt;\n}\n\u002F\u002F schedule: var h = new MoveJob { ... }.Schedule(count, 64); later h.Complete();\n```\n\n- Native containers are disposed (`Allocator.Persistent` in `OnDestroy`; `TempJob` within four frames; `Temp` within the frame).\n- Complete handles before reading results; schedule early, complete late.\n- At entity scale, consider DOTS (unity-dots-ecs) — only if the project already uses it or the task decides it.\n\n## Rendering and physics settings that cost frames\n\n- URP\u002FHDRP: keep the SRP Batcher compatible (shaders with CBUFFERs; avoid per-renderer `MaterialPropertyBlock` where it breaks batching); GPU instancing for repeated meshes; static batching for static scenery; Sprite Atlases for 2D.\n- UI: split static and frequently changing elements into separate Canvases; turn off Raycast Target on non-interactive graphics; never animate layout groups every frame.\n- Overdraw: transparent particles and full-screen effects, especially on mobile; LODs and occlusion culling for 3D.\n- Physics: the layer collision matrix trims pair checks; primitive colliders over mesh colliders on moving bodies; `Physics.autoSyncTransforms` off; tune `Time.fixedDeltaTime` deliberately.\n- Mobile: set `Application.targetFrameRate` explicitly; watch thermal throttling over minutes, not seconds.\n\n## Common Mistakes\n\n- Optimising from intuition without a Profiler capture.\n- `Instantiate`\u002F`Destroy` for bullets, hit effects and damage numbers.\n- Updating TextMeshPro text every frame with string concatenation.\n- Allocation test without a warm-up call, failing on first-call initialisation.\n- Leaking `NativeArray`s (the leak detection warning in the console is a real bug).\n\n## Red Flags\n\n- `GC.Alloc` above zero in a gameplay `Update` in the Profiler.\n- LINQ, `FindObjectsByType`, `GetComponent` or `new` inside `Update`\u002F`FixedUpdate`.\n- A performance claim in the closing message without before\u002Fafter numbers.\n",{"name":5,"source":24,"category":25,"tech_stack":26,"description":7},"informed by the Unity 6 Manual (Profiler, memory and GC, Jobs, Burst, ObjectPool, physics queries) and Unity's optimisation guides; own wording","performance","Unity","main","910394a0b6db9fc8c9a8f36328ec421d3ebd8b38","catalog\u002Fagents\u002Fgame-developer\u002Fskills\u002Funity-performance-and-gc",18,"https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper","https:\u002F\u002Ftasktrooper.ai","https:\u002F\u002Fgithub.com\u002Fmakifbaysal","Senior Software Developer","2026-11-15 04:50:29",{"source":8,"skillName":5,"commands":37,"prompt":47,"zipAvailable":48},[38,41,44],{"tool":39,"command":40},"npx","npx skills add makifbaysal\u002Ftasktrooper --skill unity-performance-and-gc",{"tool":42,"command":43},"bunx","bunx skills add makifbaysal\u002Ftasktrooper --skill unity-performance-and-gc",{"tool":45,"command":46},"pnpm","pnpm dlx skills add makifbaysal\u002Ftasktrooper --skill unity-performance-and-gc","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fgame-developer\u002Fskills\u002Funity-performance-and-gc\u002FSKILL.md",true,[],[51,57,64,71,78,85],{"skillNo":52,"name":53,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":54,"categories":55,"keywords":56,"publishedAt":19},"01M7CSVEPQW6J6TD6CS2T5FPNZ","visual-craft","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fvisual-craft\u002FSKILL.md",[],[],{"skillNo":58,"name":59,"nameZh":6,"description":60,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":61,"categories":62,"keywords":63,"publishedAt":19},"01M7CSVAQG91ETHQ0HBNZDG5FR","ux-copy","Use when you write any words a user reads in a mockup or a hand-off - content language and voice, buttons, labels, errors, empty states, confirmations, numbers and dates, and the longest-string check","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fux-copy\u002FSKILL.md",[],[],{"skillNo":65,"name":66,"nameZh":6,"description":67,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":68,"categories":69,"keywords":70,"publishedAt":19},"01M7CSV6H0J38659NDXHJQ8396","screen-mockup-html","Use when you draw screens as the design task's HTML mockup - ONE canvas document holding every screen and every variant side by side, the sanitizer-safe recipe, phone and wide frames, the states grid, static control states, and the loopback self-check with screenshots at 375, 768 and 1440 attached to the task","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fscreen-mockup-html\u002FSKILL.md",[],[],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":19},"01M7CSV3JFRF3BM3XK52M7YEYR","performance-awareness","How the performance score moves for your role. Use when the score context shows a declining trend, or before handing off work you have not self-checked against every criterion.","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fperformance-awareness\u002FSKILL.md",[],[],{"skillNo":79,"name":80,"nameZh":6,"description":81,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":19},"01M7CSTZDH00YRF5SCT7BRT9QD","design-variants","Use when a screen design needs variants - how many, variants as side-by-side rows on the one canvas, what makes two variants genuinely different, recommending one, how the human's choice is read, and narrowing to the chosen one in revision","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-variants\u002FSKILL.md",[],[],{"skillNo":86,"name":87,"nameZh":6,"description":88,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":19},"01M7CSTV6P3SM3PAE28DB0RF77","design-system-authoring","Use when you derive, change or extend a design system - where tokens live per stack, the DTCG token tree, role-based names for both themes, base vs layer vs drift, the DESIGN.md section order, the inventory format, the contrast check and the lint every proposal returns","https:\u002F\u002Fgithub.com\u002Fmakifbaysal\u002Ftasktrooper\u002Fblob\u002Fmain\u002Fcatalog\u002Fagents\u002Fui-designer\u002Fskills\u002Fdesign-system-authoring\u002FSKILL.md",[],[]]