threejs-errors-performance

Diagnose and fix Three.js performance issues including memory leaks, draw calls, and low FPS.

1|Updated Aug 20, 2023
One-click install
npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-errors-performance-imanlangaran
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: threejs-errors-performance
Source: https://github.com/imanlangaran/mini-projects/tree/main/react/three-gsap/.claude/skills/threejs-errors-performance
Command: npx skills add https://github.com/imanlangaran/mini-projects --skill threejs-errors-performance-imanlangaran

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires three, and includes references (resource) components.

What problem does it solve? Three.js scenes often suffer from low FPS, memory leaks, excessive draw calls, and high GPU memory usage caused by forgotten dispose() calls, objects created in the render loop, or missing InstancedMesh usage. This Skill provides a systematic diagnosis flowchart and proven fixes for these problems. ## Core Features & Use Cases - Performance Diagnosis: A decision flowchart built on renderer.info, Stats.js, and Chrome DevTools to pinpoint whether bottlenecks are draw calls, memory, triangles, GPU, or CPU bound. - Memory Management: Complete disposal patterns for geometries, materials, textures, render targets, controls, and full scene cleanup on component unmount. - Optimization Techniques: InstancedMesh and BatchedMesh for draw call reduction, geometry merging, LOD systems, KTX2 texture compression, object pooling, and frustum culling guidance. - Use Case: Your React Three.js app leaks GPU memory every time a viewer unmounts. Use this Skill to implement the full disposal pattern covering controls, scene traversal, material textures, and renderer cleanup. ## Quick Start Diagnose why my Three.js scene is running at low FPS and fix any memory leaks in the render loop.

Frequently Asked Questions about threejs-errors-performance

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

FAQPage Schema
How do I fix memory leaks in a Three.js scene?

Three.js memory leaks are fixed by calling dispose() on geometries, materials, textures, render targets, and controls when objects are removed. Monitor renderer.info.memory for continuously growing geometry or texture counts, which indicates undisposed GPU resources.

How to reduce draw calls in Three.js?

Reduce draw calls by using InstancedMesh for repeated objects, BatchedMesh for heterogeneous geometry, and mergeGeometries from BufferGeometryUtils for static objects. Keep draw calls under 100 for 60 FPS; over 500 is critical.

When should I use InstancedMesh instead of regular Mesh objects?

Use InstancedMesh when rendering more than about 100 copies of the same geometry and material combination. It renders thousands of instances in a single draw call, but remember to set instanceMatrix.needsUpdate = true after setMatrixAt.

Why do all my InstancedMesh instances render at the origin?

Instances render at the origin because instanceMatrix.needsUpdate was not set to true after calling setMatrixAt. The setMatrixAt method only writes to the CPU-side array; the needsUpdate flag triggers the GPU upload.

Does Three.js automatically garbage collect GPU resources?

No, Three.js GPU resources are not automatically garbage collected by JavaScript. You must manually call dispose() on BufferGeometry, Material, Texture, WebGLRenderTarget, and controls to free GPU memory and DOM event listeners.

Why does my Three.js animation stutter even with few objects?

Stuttering is often caused by allocating Vector3, Matrix4, or other objects inside the animation loop, triggering garbage collection pauses. Declare temporary math objects outside the loop and reuse them each frame.