ecs-performance-audit

Analyze ECS implementations for performance bottlenecks in entity iteration and memory allocations.

13|2|Updated Jul 17, 2023
One-click install
npx skills add https://github.com/kateusz/GameEngine --skill ecs-performance-audit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ecs-performance-audit
Source: https://github.com/kateusz/GameEngine/tree/main/.claude/skills/ecs-performance-audit
Command: npx skills add https://github.com/kateusz/GameEngine --skill ecs-performance-audit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill performs a comprehensive performance analysis of Entity Component System (ECS) implementations, identifying bottlenecks, memory allocation issues, and cache coherency problems that directly impact frame rate. It helps developers optimize entity processing, system execution order, and data access patterns for maximum game performance.

Core Features & Use Cases

  • System Iteration Analysis: Identifies inefficient entity iteration patterns, O(n²) algorithms, and unnecessary LINQ allocations in hot loops.
  • Priority & Ordering Validation: Verifies system execution order and suggests adjustments for better parallelization potential.
  • Memory Allocation Detection: Flags allocations in OnUpdate(), Render(), and OnEvent() loops, including boxing, LINQ materializations, and closure captures.
  • Data Locality & Cache Coherency: Evaluates component data layout and suggests cache-friendly packing strategies.
  • Use Case: If the game experiences frame rate drops when many entities are active, this Skill can audit the RenderingSystem to identify excessive allocations in its OnUpdate() method, suggest replacing .ToList() with direct iteration, and recommend optimizing component data access for better cache performance.

Quick Start

Analyze the RenderingSystem.cs for any LINQ materializations in its OnUpdate() loop that might be causing unnecessary memory allocations.

Frequently Asked Questions about ecs-performance-audit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I identify performance bottlenecks in my ECS implementation?

Performance bottlenecks in ECS stem from inefficient entity iteration, excessive memory allocations in hot loops, and poor cache coherency. Analyze your OnUpdate and rendering loops for LINQ materializations (.ToList, .ToArray), boxing, closure captures, and O(n²) patterns. Profile frame-time drops by inspecting system execution order, component data layout (Structure of Arrays vs Array of Structures), and reflection usage to pinpoint the slowest paths.

What causes frame rate drops with large entity counts in ECS games?

Frame rate drops under heavy entity counts typically result from memory allocations in tight loops, inefficient component lookups, and poor data locality. LINQ allocations, reflection in tight paths, suboptimal system scheduling order, and cache-incoherent data access patterns force the CPU to stall. Audit your iteration patterns and prioritize eliminating allocations and optimizing data layout for sequential memory access.

How do I optimize entity iteration and system scheduling for better performance?

Optimize entity iteration by replacing LINQ materializations with direct iteration, eliminating boxing and closure captures, and validating system execution order for parallelization potential. Restructure component data layout for cache coherency—prefer Structure of Arrays over Array of Structures—and reduce reflection usage. Measure allocations and frame time before and after each change to quantify performance gains.

Can I use ECS performance optimization with C# game engines?

Yes. ECS performance optimization targets C# implementations by analyzing OnUpdate loops, rendering systems, and event handlers for allocation patterns, data layout efficiency, and cache coherency. The approach applies directly to C#-based game engines and custom ECS frameworks, focusing on LINQ usage, component access patterns, and memory allocation detection in hot paths.

What memory allocation issues should I look for in ECS OnUpdate loops?

Watch for LINQ materializations (.ToList, .ToArray, .Where/.Select), boxing from value types, closure captures in delegates, and reflection-based component lookups in tight loops. These allocations fragment the heap, increase garbage collection pressure, and cause frame stutters. Refactor to use direct iteration, pre-computed component handles, and stack-allocated structures to eliminate per-frame allocations.

How does cache coherency affect ECS performance?

Cache coherency determines whether CPU caches can efficiently access entity component data. Array of Structures layouts scatter related components across memory, causing cache misses. Structure of Arrays packs each component type contiguously, enabling sequential memory access and cache-friendly prefetching. Poor data locality forces expensive main-memory stalls; optimizing layout can significantly reduce frame time under large entity counts.