Notes 3D on the web, part 2

What 60 fps costs

16 November 2026 3 min read

Part 2 of 3D on the web. Four knobs on one scene, a frame budget, and a live reading of what each knob costs on your device.

  • WebGL
  • Performance
  • Battery

Part one was about when the picture appears. This part is about what the scene costs once it runs. A 3D scene is a loop that has to finish its work before the next screen refresh. At 60 frames per second you have 16.7 milliseconds, and the browser needs some of them too.

A rotating orange blob, drawn live.

Scroll this out of view with "pause" on, and the drawn count falls to 0.

Time to draw one frame

…ms

measuring · budget at 60 fps is 16.7 ms

0 frames drawn in the last second

The time is measured by drawing a frame and waiting for the GPU to finish it. That stall is only for measuring and would hurt a real page. On a laptop without a strong GPU, or in a browser that draws in software, the same scene costs far more than on a recent phone. The relative changes are what to look at.

Live demo. Everything runs in your browser. Now try to break it.
FrameBudget.svelte, 178 lines

The bar shows how much of that budget one frame uses, measured on your device. Move one slider at a time and watch it.

The four knobs

Resolution. The cost of a frame is mostly the number of pixels times the work for each pixel. Double the width and height and you pay four times. This is why device pixel ratio matters: a phone that reports 3 draws nine times the pixels of a screen at 1. Rendering at the full ratio is rarely worth it for something soft and moving, and a cap of 1.5 or 2 is common.

const dpr = Math.min(window.devicePixelRatio || 1, 1.5);
canvas.width = Math.round(cssWidth * dpr);
canvas.height = Math.round(cssHeight * dpr);

Work per pixel. In this scene every pixel asks "how far is the surface?" many times while it walks a ray towards the blob, and each layer of surface detail makes every one of those questions more expensive. The slider is the number of layers. The cost is multiplied by the pixels, every frame. A shader that looks the same with fewer layers is free speed. It is hard to see and easy to measure.

Frame rate. A slow, ambient motion looks the same at 30 frames per second as at 60 and costs half. Capped here by skipping frames. That halves the load on the GPU and on the battery. Fast interaction, such as dragging an object, is different and deserves the full rate.

Pausing. The cheapest frame is the one you do not draw. A hero scene that is scrolled away, or in a hidden tab, should draw nothing. The browser already pauses requestAnimationFrame in a hidden tab. Off screen in the same tab it does not.

const io = new IntersectionObserver(([e]) => (visible = e.isIntersecting));
io.observe(canvas);

function loop(t) {
  requestAnimationFrame(loop);
  if (!visible) return;
  draw(t);
}

Scroll the demo out of view and look at the counter: with "pause" on, it falls to zero.

Why the budget is smaller than it looks

The browser also has to run your scripts, handle input and compose the page, and on a phone the chip slows itself down when it gets hot. A frame that uses 14 of 16.7 milliseconds on your desk will drop frames in a pocket after a minute. A comfortable reading is one around half the budget.

The library question

For a single effect like this one, a library is most of what you download. A general 3D library is in the range of a hundred kilobytes or more gzipped, even when you import only what you use, and a shader like this one is a couple of kilobytes. The library earns its size once you have models, lights, loaders, cameras and many objects. Check with a bundle analyzer rather than trust a number from an article, including this one.

How to measure on your own page

  • Chrome's Performance panel shows each frame and the time the GPU needs.
  • Most libraries expose counters for draw calls and triangles. A high number of draw calls is often the first problem in a real scene.
  • Test on the slowest device people use, not on your own. A throttled CPU in developer tools is a start, not a replacement.

About the readings

The demo draws a frame and waits for the GPU to finish it, to get an honest time. That wait would hurt a real page, so do not copy it into production. In a software-only browser the numbers will be many times larger than on a phone with a GPU. What matters is how they change as you move the sliders.

Series: 3D on the web

What it costs, who it leaves out, and how to do it without hurting the page.

  1. Part 1The hero that does not block your LCP
  2. Part 2What 60 fps costs

More parts will follow.

Related

How bright was it?

Five lamps and an optional line. Feedback, a bug, an idea, anything. I read every one and sum them up once a month.

Pick a lamp

Stored without name, address or cookie, and deleted after a year. Details in the privacy notice.