Your Three.js demo runs at 60 fps on your laptop and 12 fps on a phone. Here's why.
Your demo runs at 60 fps on a laptop and 12 fps on a phone. It is rarely one bug. It is usually the same five mistakes — and all five are cheap to fix.
1. Cap the pixel ratio
A phone with a 3x display asks the renderer for nine times the pixels of a 1x canvas. Most scenes do not need that. Cap it at 2, and at 1.5 if the scene is heavy.
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); This one line is often the difference between a stuttering demo and a smooth one. Test it on a real mid-range phone, not just a flagship.
2. Reuse geometry and materials
Creating a new BoxGeometry and a new MeshStandardMaterial for every object is a common habit, and it is expensive. Share one geometry and one material across identical objects, and change only what differs — position, rotation, scale.
const geo = new THREE.BoxGeometry(1, 1, 1); const mat = new THREE.MeshStandardMaterial({ color: 0x6366f1 }); for (let i = 0; i < 200; i++) { const mesh = new THREE.Mesh(geo, mat); mesh.position.set(i % 20, 0, Math.floor(i / 20)); scene.add(mesh); } 3. Count your draw calls
Two hundred meshes can mean two hundred draw calls, and the CPU cost of those calls is what kills mobile. Merge static geometry where you can, use InstancedMesh for repeated objects, and hide what is off-screen instead of drawing it anyway.
const instanced = new THREE.InstancedMesh(geo, mat, 200); instanced.instanceMatrix.needsUpdate = true; 4. Shrink your textures
A 4K texture on a phone is wasted memory and wasted bandwidth. Use the smallest texture that still looks good at the size it is actually shown, compress it, and prefer one texture atlas over many small files.
- Hero textures: 1024px is usually enough on mobile.
- Small props and icons: 256px or less.
- Always test with the network throttled — a demo that loads in 2 seconds on Wi-Fi can take 12 on 4G.
5. Keep the animation loop honest
Do not allocate inside requestAnimationFrame. No new vectors, no new arrays, no string building per frame. Allocate once, reuse every frame, and use delta time so the motion stays correct at any frame rate.
const clock = new THREE.Clock(); const tmp = new THREE.Vector3(); function animate() { requestAnimationFrame(animate); const dt = Math.min(clock.getDelta(), 0.05); tmp.set(Math.sin(dt), 0, 0); renderer.render(scene, camera); } The rule of thumb: if it runs at 60 fps on a three-year-old phone, it will run anywhere. Profile on the weakest device you can find, fix the biggest cost first, and only then add more effects.
None of this is glamorous. That is the point — performance work is mostly removing waste, not adding cleverness. Do these five, measure again, and your demo will feel like a different project.
Try it live: here's a small live demo built on the same idea — a gradient & glass studio you can tune right in the feed: https://devlyo.com/p/748790a0-53e6-4509-a341-a7c5b418ad8b
I build on Devlyo — a social network for developers where live code runs right in the feed instead of as a screenshot. Post a Three.js scene or a demo, people run it, tweak the knobs, remix it with credit, and leave feedback on the code itself. Joining is free, and early creators get featured while every post is still seen. What would you post first?