agentleFS
skysepehruskysepehru/unity-claude-skills/skills/unity-performance/SKILL.md

unity-performance

Skill1 starsChanged 5 months agoMITView on GitHub

Performance best practices for Unity C# code - allocations, hot paths, GC pressure. ALWAYS Auto-loaded when writing code for Unity Projects.

5 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use unity-audio.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • aluminumBathSkill

    unity-audio

    Implement and polish Unity audio architecture, mixers, spatial sound, music transitions, ambience, pooling, ducking, and accessibility.

    Also in 3 projects that use this

The file

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 1

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Follow these conventions to avoid common performance pitfalls in Unity C# code.

    line 7
  2. Very specific:

    Use manual for/foreach loops instead.

    line 13
  3. Very specific:

    Do not create new collections (new List<T>()) in methods called frequently — pre-allocate and reuse.

    line 18
  4. Very specific:

    Avoid boxing value types (passing structs as object).

    line 23

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Unity Performance Conventions

Follow these conventions to avoid common performance pitfalls in Unity C# code.

LINQ & Allocations in Hot Paths

  • Never use LINQ in hot paths — Update(), FixedUpdate(), input handlers, physics callbacks, and any method called frequently.
  • LINQ methods (Where, FirstOrDefault, Select, etc.) allocate enumerator objects on each call, creating GC pressure.
  • Use manual for/foreach loops instead.
  • Properties that expose LINQ queries (e.g., public IEnumerable<T> ActiveItems => _items.Where(...)) allocate on every access — cache the result or use manual iteration.

Collection Allocation

  • Do not create new collections (new List<T>()) in methods called frequently — pre-allocate and reuse.
  • For methods that return filtered subsets, prefer passing in a pre-allocated list to fill, or cache the result and invalidate on change.

General GC Awareness

  • Avoid boxing value types (passing structs as object).
  • String concatenation in hot paths — use StringBuilder or string.Create.
  • Closures/lambdas in hot paths capture variables and allocate — extract to methods when possible.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.