A 3D portfolio that doesn't cook your laptop
The first version of this desk ran my laptop hot. Nothing on screen was moving. The page was redrawing a full 3D scene as fast as the display allowed, to show what was, most of the time, a still picture.
A still desk doesn't need 60 frames
The fix was to stop letting the browser decide. The page now draws a frame only when one is needed, and how often depends on what is happening:
- 60 a second while something moves: your pointer, the camera, an animation. Never more, even on a 120 Hz screen.
- About 20 when the desk is still. Only the print grain and the coffee steam drift.
- 8 while another window has your attention.
- None once you are inside the computer and the desk is out of sight.
Anything that moves on its own after a click, like a draft flying out of the bin, asks for full speed for as long as it needs it.
// "I'm still moving": full rate for a moment longer
function keepAwake(ms = 400) {
awakeUntil = Math.max(awakeUntil, performance.now() + ms);
}
Pixels are the other budget
A sharp screen has four times the pixels of a normal one, and the print shader touches every one of them. So pixel density is capped at 2x and at roughly eight million pixels in total. If a device still can't keep up, density steps down a little.
The cheapest frame is the one you never draw.
Test on the hardware your visitors have, not the one you build on. And put your hand on the laptop. It is a surprisingly good profiler.