Optimize GPU rendering in WebGL, three.js, Pixi and Phaser games. Measure draw calls, triangles, textures and frame time in the viewer's browser (never the sandbox), then reduce draw calls (instancing, merging, atlases, fewer materials), fill rate (pixel ratio, overdraw, transparent layers, post-processing), shader cost, shadow cost, texture memory (sizes, compression, mipmaps), avoid CPU-GPU s...
Download skill (.zip) Files on GitHubWebGL performance
Measure in the viewer’s browser (look_at_preview, read_preview_console) or with check_gpu_render. The sandbox
browser has no GPU and must not load these pages.
Measure
// three.js: log once per second (or show in a debug overlay)
const i = renderer.info;
console.log(`[gpu] calls ${i.render.calls} · tris ${i.render.triangles} · geos ${i.memory.geometries} · tex ${i.memory.textures} · programs ${i.programs.length}`);
Add game-performance-profiling’s perf-probe.js for fps and frame times. Find out which side is slow: halve the pixel ratio.
If fps jumps, you’re fill-bound (pixels). If not, you’re draw-call / CPU bound.
| Budget (mid phone) | Target |
|---|---|
| Draw calls | < 100–200 |
| Triangles | < 300k–500k |
| Pixel ratio | ≤ 1.5–2 |
| Texture memory | < 150–256 MB |
| Shadow-casting lights | 1 |
Fewer draw calls
InstancedMeshfor anything repeated (trees, rocks, coins, bullets, crowds). One call for thousands.- Merge static geometry (
BufferGeometryUtils.mergeGeometries) per material and area. - Share materials. Every unique material and texture combination breaks batching. Use texture atlases.
- Pixi / Phaser: keep sprites from the same atlas together; avoid interleaving text, graphics and sprites (each switch breaks the batch).
Fewer pixels (fill rate)
renderer.setPixelRatio(Math.min(devicePixelRatio, 1.5))on phones; adaptive drop when slow.- Overdraw: big transparent particles, stacked full-screen UI or fog planes. Use smaller, fewer, opaque where possible.
- Post-processing (bloom, SSAO, DOF) is very expensive on phones: off by default, or half resolution.
- Shorter camera far plane + fog hides cut-off distance.
Cheaper shading
MeshLambertMaterial/MeshBasicMaterialinstead ofMeshStandardMaterialwhen PBR isn’t needed. Bake lighting into textures.- Shadows: one directional light, 1024–2048 map, tight shadow camera following the player,
castShadowonly on key objects; static scenes: bake shadows, orrenderer.shadowMap.autoUpdate = falseand update on change. - Custom shaders: avoid branches and loops per pixel, use lower precision (
mediump) where safe.
Textures and memory
- Power-of-two, ≤ 1024–2048 px, mipmaps on; KTX2 / Basis compressed textures for big sets (smaller in GPU memory too).
dispose()geometries, materials, textures and render targets you remove. Watchrenderer.info.memoryacross restarts.
Hitches and stalls
- Shader compile on first appearance:
renderer.compile(scene, camera)during loading; show every effect once off-screen. - Don’t read back from the GPU per frame (
readPixels,getImageDataon a WebGL canvas). - Avoid creating new materials or geometries during play: pool them.
Context loss
Phones drop WebGL contexts under memory pressure. Listen for webglcontextlost (preventDefault) and webglcontextrestored;
at minimum show “Tap to reload” instead of a frozen frame.
Report
“Draw calls 1,240 → 96 (instanced trees and coins, merged level); pixel ratio 2 → 1.5 on phones; 34 → 60 fps in your preview.”