Split The code is public; the app answers only to the crew.

Hold 60 fps on a laptop and a phone: adapt the render scale to the frame time #14

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Pushed. bun test passes (130 tests, 11 of them new in src/client/quality.test.ts), the bundle is rebuilt and committed, and / answers in 5.7 ms locally. The render scale is now a decision rather than a constant.

Notes

shipped merged

opened this

Pushed. bun test passes (130 tests, 11 of them new in src/client/quality.test.ts), the bundle is rebuilt and committed, and / answers in 5.7 ms locally.

The render scale is now a decision rather than a constant. src/client/quality.ts holds a pure nextRenderScale(scale, frameMs): a dead band from 0.9 × 16.7 ms to 1.25 × 16.7 ms that contains the 60 fps target, a down step of 0.1 against an up step of 0.05 (losing frames is worse than losing pixels), and a clamp of 0.5 to 1 of the capped device pixel ratio. renderer.resize() multiplies the ratio by a scale handed to it through setScale; main.ts calls the decision at most twice a second from the smoothed frameAverage, never from the frame that just ran long. The HUD canvas keeps the full device ratio so text stays crisp, the CSS size of #stage is untouched, and #fps appends · 70% res only when the scale is below 1 — the fps stays the frame time.

Measurement, and the part of it I could not do: this sandbox has no GPU and no browser, so the before/after frame times at 1280×720 and at 360px wide are not measured and I will not invent them. What I did measure here, on the sandbox CPU: the simulation is 0.102 ms/tick for a 10-player world (3,840 ticks in 391 ms), i.e. ~0.11 ms of CPU in a 16.7 ms frame — so essentially the whole budget is pixels, which is why the buffer is the right knob. The exact pixel budgets the change moves, from the real layout (main capped at 64rem, 16/9 above 640px and 4/3 below): laptop at 1280×720 with dpr 2 → 1984×1116 = 2.21 Mpx at scale 1, 1.08 Mpx at 0.7, 0.55 Mpx at 0.5; phone at 360 wide with dpr 3 (capped to 2) → 656×492 = 0.32 Mpx at scale 1, 0.16 at 0.7, 0.08 at 0.5. A closed-loop test stands in for the profile: fed a frame time that follows the pixel count, the controller settles at the largest scale under the band and then stays there, instead of walking across the edge.

To try it in the preview, play a round and watch the corner counter; to force the path, throttle the GPU in devtools (or open it on a phone) and the readout should fall to … ms · 70% res within a second or two without the page shifting. The limitation is documented in the module and the README: a display locked to 60 Hz reports one vsync period however early the frame finished, so a machine that stepped down cannot prove it got its headroom back and keeps the smaller buffer — the climb back is for displays with headroom to show. I did not add a manual quality setting or a resolution slider; that is a separate change.

🤖 Generated with Claude Code

Closes #12

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs