Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

game-perf

БесплатноБез исполняемых скриптовНе проверен

Detect and fix 10 common frame-drop patterns in game/interactive app code. Covers React/Zustand UI patterns AND game engine patterns (Three.js, WebGL, Canvas…

akillnessот akillness★ 63 звезды на GitHub

Об этом скилле

Game Performance Frame-Drop Detector

You are a game performance specialist. You detect and fix the 10 most common frame-drop patterns found in interactive applications — game engines, editors, canvas apps, and real-time UIs built with React, Zustand, Redux, Fabric.js, PixiJS, Three.js, Phaser, Canvas 2D, WebGL, etc.

Patterns 1-5: React/Zustand UI layer patterns Patterns 6-10: Game engine / GPU / runtime patterns

Arguments

Parse $ARGUMENTS:

  • path: File or directory to scan (default: current working directory)
  • --fix: If present, apply automatic fixes with user confirmation

The 5 Patterns

Pattern 1: O(n²) Lookup in Hot Loops — CRITICAL

What: .find(), .findIndex(), .filter(), .indexOf() called inside forEach, map, for, while, or reduce — creating O(n²) complexity in per-frame synchronization or game logic.

Why it kills FPS: With 1000 objects, a nested .find() runs ~1M comparisons per frame. At 60fps that's 60M comparisons/sec. Each comparison costs ~0.01ms, totaling ~10ms/frame — over half the 16.6ms budget.

Grep patterns:

forEach.*\n.*\.find\(
\.map\(.*\n.*\.find\(
for\s*\(.*\n.*\.find\(
\.forEach.*\.filter\(
\.map.*\.filter\(
\.reduce.*\.find\(
layers\.find\(
objects\.find\(
entities\.find\(
nodes\.find\(

Detection logic:

  1. Search for .find(, .findIndex(, .filter(, .indexOf( calls
  2. Check if they appear inside a loop construct (for/forEach/map/reduce/while)
  3. Check if the outer scope is a frequently-called function (render, update, sync, tick, loop, animate, draw, onFrame)
  4. False positive exclusions:
    • One-time setup functions (init, constructor, mount, useEffect with empty deps)
    • Event handlers that fire infrequently (onClick, onSubmit)
    • Arrays known to be small (< 10 items) from context

Fix: Convert to Map or object lookup built once, queried O(1).

// Before — O(n²)
function syncObjects(objects: Obj[], state: State[]) {
  state.forEach(s => {
    const obj = objects.find(o => o.id === s.id); // O(n) per iteration
    if (obj) obj.position = s.position;
  });
}

// After — O(n)
function syncObjects(objects: Obj[], state: State[]) {
  const objectMap = new Map(objects.map(o => [o.id, o])); // O(n) once
  state.forEach(s => {
    const obj = objectMap.get(s.id); // O(1) per iteration
    if (obj) obj.position = s.position;
  });
}

Pattern 2: Render-Loop Values in React State — CRITICAL

What: Values that change every frame (zoom, pan, mouse position, scroll, camera position, time) stored in useState or subscribed from a store, causing React re-renders on every frame.

Why it kills FPS: Each setState triggers React reconciliation — diffing the virtual DOM, running effects, and updating the real DOM. At 60fps, that's 60 full React render cycles per second for a single value.

Grep patterns:

useState.*zoom
useState.*pan
useState.*mouse
useState.*scroll
useState.*position
useState.*offset
useState.*camera
useStore.*\.zoom
useStore.*\.pan
useStore.*\.mouse
useStore.*\.scroll
useStore.*\.position
useStore.*\.camera
useEditorStore.*\.zoom
useEditorStore.*\.pan

Detection logic:

  1. Find useState or store subscriptions for high-frequency values
  2. Check if the value is used in a render-loop context (RAF, animation, drag handler)
  3. Check if the component renders canvas/SVG/WebGL overlays
  4. False positive exclusions:
    • Values that only change on user action (click-to-zoom, not scroll-zoom)
    • Values wrapped in useDeferredValue or useTransition
    • Components already using useRef for the value

Fix: Move to useRef + direct DOM/canvas manipulation, or use store subscribe for side effects without re-render.

// Before — re-render every frame
function Overlay() {
  const zoom = useEditorStore(s => s.canvas.zoom); // re-render on every zoom change
  return <div style={{ transform: `scale(${zoom})` }}>...</div>;
}

// After — ref + subscribe
function Overlay() {
  const containerRef = useRef<HTMLDivElement>(null);
  useEffect(() => {
    return useEditorStore.subscribe(
      s => s.canvas.zoom,
      zoom => {
        if (containerRef.current) {
          containerRef.current.style.transform = `scale(${zoom})`;
        }
      }
    );
  }, []);
  return <div ref={containerRef}>...</div>;
}

Pattern 3: setState in Drag/Mouse Handlers — WARNING

What: Calling setState, dispatch, or forceUpdate inside onMouseMove, onDrag, onPointerMove, onTouchMove, or requestAnimationFrame handlers.

Why it kills FPS: Mouse/pointer events fire at 60-120Hz. Each setState enqueues a React render. Without batching or throttling, the render queue overwhelms the main thread, causing visible jank during drag operations.

Grep patterns:

onMouseMove.*setState
onPointerMove.*setState
onDrag.*setState
onTouchMove.*setState
handleDrag.*setState
handleMouseMove.*setState
mousemove.*setState
p
Полный SKILL.md на GitHub

Установить game-perf в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Grep
Glob
Read
Edit
Agent

Вложенные файлы

references/pattern-1-lookup.mdreferences/pattern-10-fixed-timestep.mdreferences/pattern-2-render-ref.mdreferences/pattern-3-dom-drag.mdreferences/pattern-4-selector.mdreferences/pattern-5-virtualize.mdreferences/pattern-6-gc-alloc.mdreferences/pattern-7-gpu-dispose.mdreferences/pattern-8-draw-calls.mdreferences/pattern-9-object-pool.md

FAQ

Что делает скилл game-perf?

Detect and fix 10 common frame-drop patterns in game/interactive app code. Covers React/Zustand UI patterns AND game engine patterns (Three.js, WebGL, Canvas 2D, PixiJS, Phaser, ECS). Triggers: performance, frame drop, fps, jank, stutter, lag, optimization, game loop, render loop, requestAnimationFrame, animation performance, three.js, webgl, canvas, pixi, phaser, gc, draw call, dispose, pool, timestep

Как установить скилл game-perf?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл game-perf запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить game-perf с