web-3d-perf
Skill8 starsChanged 11 days agoMITView on GitHub
Frame-budget rules for 3D and heavy canvas work on the web (React Three Fiber, Three.js, WebGL): pixel-ratio cap, pause when offscreen or hidden, instancing, disposal, lazy loading, reduced-motion fallback, and how to measure. Use when building or reviewing a 3D scene, a shader background or a canvas animation, and always under the immersive UI profile.
In this repository23 other files it gives its agents.
- skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- animateSkill
- animation-performanceSkill
- choreographSkill
- crew-briefSkill
- crew-handoffSkill
- crew-lintSkill
- crew-modeSkill
- crew-nightSkill
- crew-researchSkill
- crew-routingSkill
- crew-setupSkill
- design-taste-frontendSkill
- frontend-designSkill
- frontend-ui-engineeringSkill
- interaction-designSkill
- remove-animationsSkill
- security-auditSkill
- securitySkill
- thesvgSkill
- ui-ux-pro-maxSkill
- vercel-react-best-practicesSkill
- web-design-guidelinesSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 5 are distinctive, and 6 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 16
Before writing the scene, write down (in the profile's perfBudget or the PR notes):
- Very specific: line 26
Render on demand: when the scene is mostly still: frameloop="demand" and call invalidate() after a change.
- Very specific: line 29
Do not allocate in the loop: no new Vector3(), clone(), array or object literals inside useFrame.
- Distinctive: line 36
Textures: use compressed GPU formats (KTX2/Basis) for anything large, power-of-two sizes, no larger than it will appear (a 4096 map on a …
- Distinctive: line 38
Shaders: keep fragment shaders short.
- Very specific: line 43
When a scene, route or object goes away, call dispose() on its geometries, materials, textures and render targets (drei and R3F dispose …
- Very specific: line 44
Check the result: renderer.info.memory (geometries, textures) and renderer.info.render (calls, triangles) must return to their earlier …
- Distinctive: line 51
Do not mount the canvas until it is near the viewport.
- Distinctive: line 57
Keep the page usable without the scene: text, links and controls live in the DOM, not inside the canvas.
- Very specific: line 62
Use Stats (stats.js, or drei Stats) for a live frame time, and renderer.info for draw calls, triangles and memory.
- Distinctive: line 63
Test with CPU throttling (4x) and a phone, not only the development machine.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Web 3D performance
Written for crew-chief in its own words. The goal is a scene that holds its frame rate on a mid-range laptop and a phone, costs nothing while nobody sees it, and still works for people who ask for less motion. Every rule below is checkable: when you finish, go through the list and name the ones you could not meet.
0. Real 3D only
Under the immersive profile the hero or main scene must be real 3D: Three.js/WebGL, with react-three-fiber when the project is React. A CSS or SVG imitation (layered gradients, rotated divs, a looped video of a scene) is not acceptable. If you cannot build real 3D (a stated constraint, no WebGL available), say so explicitly in your report with the reason, and do not substitute without saying.
1. Set the budget first
Before writing the scene, write down (in the profile's perfBudget or the PR notes):
- target frame time: 16.6 ms for 60 fps (8.3 ms for 120 Hz screens, but do not promise it);
- a draw-call ceiling (about 100 on desktop, 50 on phones is a sane start), a triangle ceiling, a texture memory ceiling;
- the weakest device you care about.
A scene with no number is a scene nobody can call too slow.
2. Render only what is needed
- Cap the pixel ratio.
dpr={[1, 2]}in R3F, orrenderer.setPixelRatio(Math.min(devicePixelRatio, 2)). Rendering at 3x on a phone costs 2.25 times the pixels of 2x and nobody sees the difference. Drop to 1.25 or lower if frames are late (R3F'sPerformanceMonitorcan step it down and up). - Render on demand when the scene is mostly still:
frameloop="demand"and callinvalidate()after a change. A constantly running loop for a static product shot burns a battery for nothing. - Pause when it cannot be seen. Stop the loop when the canvas is offscreen (
IntersectionObserver) and when the tab is hidden (document.visibilityState, orframeloop="never"while hidden). Resume cleanly, without a time jump: use the clock delta, clamp it (about 0.05 s), and never advance animation by wall-clock time. - Do per-frame work in the frame callback, not in React state. Never call
setStateinsideuseFrame; write to refs, uniforms, or instance matrices. One state update per frame re-renders the tree and ruins the budget. - Do not allocate in the loop: no
new Vector3(),clone(), array or object literals insideuseFrame. Create the scratch objects once outside and reuse them.
3. Cut the work the GPU does
- Instance repeats. The same mesh more than a few times is one
InstancedMesh(or dreiInstances), updated through the instance matrix, not hundreds of meshes. Merge static geometry that never moves on its own (BufferGeometryUtils.mergeGeometries). - Share geometry and materials. One geometry and one material object per kind, not one per mesh. Different material objects mean extra draw calls and extra shader programs.
- Keep shadows, transmission, and post-processing deliberate. Each is a full extra pass. Bake static shadows and lighting into textures where you can; use one or two real lights; limit the shadow map size; add post effects one at a time and measure each.
- Textures: use compressed GPU formats (KTX2/Basis) for anything large, power-of-two sizes, no larger than it will appear (a 4096 map on a 300 px object is waste), mipmaps on. Prefer a texture atlas over many small ones.
- Models: compress meshes (Draco or Meshopt), strip unused attributes, decimate what is far away, and use level of detail where the camera range is wide.
- Shaders: keep fragment shaders short; avoid branching on varying values and loops with a runtime bound; do not recompute in the fragment what the vertex stage can give you.
4. Free what you stop using
Three.js does not free GPU memory when a JavaScript reference disappears.
- When a scene, route or object goes away, call
dispose()on its geometries, materials, textures and render targets (drei and R3F dispose automatically for objects they mount; anything you create by hand withnewis yours). - Check the result:
renderer.info.memory(geometries, textures) andrenderer.info.render(calls, triangles) must return to their earlier numbers after leaving and re-entering a screen. A count that only grows is a leak. - One WebGL context per page where possible; browsers drop old contexts when many exist.
5. Load it late
- The 3D bundle is heavy: load it with a dynamic import (
next/dynamicwithssr: false, orReact.lazy) only where the scene appears, not in the main bundle. - Show a lightweight placeholder (a poster image of the same size, so the layout does not jump) until the scene is ready; load models and textures after the first paint, with a progress state.
- Do not mount the canvas until it is near the viewport.
6. Respect reduced motion and weak hardware
prefers-reduced-motion: reducemust change the result: show a still frame (or render once withframeloop="demand"), stop camera drift, parallax and autoplay, keep only motion the user starts.- Provide a fallback when WebGL is missing or the context is lost: a static image, not a blank box. Listen for
webglcontextlostandwebglcontextrestored. - Keep the page usable without the scene: text, links and controls live in the DOM, not inside the canvas; give the canvas an accessible name or mark it decorative.
7. Measure, do not guess
- Open the browser's Performance panel, record 5 to 10 seconds of the real interaction, and look at the frame bars and the main-thread and GPU rows. Frames over the budget are the work list.
- Use Stats (
stats.js, or dreiStats) for a live frame time, andrenderer.infofor draw calls, triangles and memory. - Test with CPU throttling (4x) and a phone, not only the development machine; throttle the GPU by a smaller window and a larger pixel ratio.
- Change one thing at a time and re-measure. Keep the number you saw in the report ("120 draw calls to 18 after instancing; 9.8 ms per frame").
Checklist before you report done
- A written budget exists (frame time, draw calls, memory, weakest device).
- Pixel ratio is capped; on-demand rendering is used when the scene is mostly still.
- The loop stops offscreen and in a hidden tab, and resumes without a time jump.
- No
setStateand no allocation inside the frame callback. - Repeats are instanced; geometry and materials are shared.
- Created resources are disposed;
renderer.info.memoryreturns to baseline after a route change. - The scene loads lazily with a same-size placeholder.
prefers-reduced-motiongives a still or minimal result; there is a no-WebGL fallback; the page works without the canvas.- A measurement from the performance panel or
renderer.infois quoted in the report; if none was taken, the report saysnot verified.
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
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.

