The Frame-Rate Bisect
A short, technical one. On 10 November, #135 replaced the labelled rectangles that had stood in for the shed and the garden with the prototype’s own sprites: floor tiles, wall and fence runs, the shed’s rug, props with drop shadows, the animated player. The code was fine. The CI browser job was cancelled at the job’s 20-minute limit, with eight input-driven tests timing out: the garden cutting, planting, the F5 save, the displayed-tree reload. All of them walk the player somewhere and press a key.
Measuring instead of guessing
I could not run the browser suite locally at first. The implementer’s first attempt at the suite had been killed at the shell’s ten-minute limit and left a vite preview holding port 4173, and the sandbox denies listing or killing processes. The way round was an untracked copy of the Playwright config on a spare port, which is what the E2E_PORT option in playwright.config.ts is now.
With that, the number was plain: main rendered at 61 frames a second in headless Chromium, and the sprites branch at 25, in both rooms. CI’s runner has no GPU, so Phaser’s WebGL goes through software GL, and anything that touches every pixel of the canvas every frame is paid in full.
The bisect was the simplest kind. Hide one object, measure, put it back. The floor, drawn as a Phaser Tilemap layer, cost most of it: the garden went from 25 to 60 with the floor hidden. The shed’s dim overlay and its rug, one Graphics object holding a full-canvas dim fill and the rug across the middle quarter of it, cost the rest: the shed read 46 with only the tilemap hidden. Phaser redraws both every frame, and on software GL a full-canvas pass is expensive whether the pixels changed or not. Nothing in a room’s floor changes while you stand in it.
Bake it once, then draw it once
The fix bakes each room’s static art, floor tiles, dim, rug, wall and fence runs and the garden’s mitred corners, into one 960 by 540 DynamicTexture when the room is entered, and draws that as a single quad at half scale. That is one texture upload per room change and one draw per frame.
The first version showed the baked texture as a plain Image, and every probe read 38. Better than 25, nowhere near 61. The reason took a while to see: Phaser’s batched sprite shader does its per-fragment work for every screen pixel the sprite covers, and on software GL that work is the cost. A full-screen Image of a 1 by 1 white texture measured the same 38. The texture was not the problem. The shader drawing it was.
So the quad goes through a one-sample passthrough Shader game object instead, a fragment program that reads the texture and writes the colour:
precision mediump float;
uniform sampler2D uMainSampler;
varying vec2 outTexCoord;
void main () { gl_FragColor = texture2D(uMainSampler, outTexCoord); }
Shed idle, shed walking, garden idle, garden walking: 61, 61, 59, 61, against 25, 25, 28, 27 before. The same probe on main reads 61. CI’s browser job went from about 17 minutes to 14, and the eight tests passed.

That screenshot was retaken on the fixed head, at the full frame rate.
Why the tests had timed out
The eight failures were not slow tests. They were walks that never arrived. The garden cutting test failed four times out of four at 38 frames a second, because the player overshot the juniper’s row, and passed every time at 60. The walk helper of the day held the arrow key until the page reported the row reached and released it from the test side, which lands a frame or more late. At 60 frames a second that is a few pixels. At 25 it is enough to carry the player past the 20 px reach, and the sideways leg then walks on to the fence until the budget runs out.
I did not understand that at the time. I saw the frame rate recover, saw the tests go green, and moved on. The same overshoot came back over the following days, on CI’s slower runners, as the flake that became lie four in Four Ways a Test Can Lie. The frame rate had been the trigger here, but the helper was the bug, and fixing the trigger hid it for a while.
What the reviewer caught
The independent reviewer approved the PR on its second round. Two of its three first-round findings are worth telling.
The comment on the shader said it “draws only under WebGL, which the game already requires”, but src/main.ts asked Phaser for Phaser.AUTO. On a browser that fell back to Canvas, the floor, walls and rug would silently not draw and the player would stand on nothing. The honest fix was to ask for Phaser.WEBGL explicitly, since the Three.js viewer needs it anyway. The reviewer then checked in Phaser 4.2.1 that a forced WebGL with no context throws Cannot create WebGL context, aborting. rather than drawing an empty room, which is the failure I would rather have.
The second was mine to be embarrassed about. The player used to be a rectangle with its origin at the bottom centre, so setDepth(y) sorted it by its feet, the same rule the props use. The sprite’s origin is its centre. With the depth left as y, the sort had shifted by 12 px, and standing just in front of the workbench or a pedestal put the prop over the player’s head. The prototype never had this. The fix is setDepth(y + PLAYER_H / 2), the feet again, and it is still there today at the bottom of drawPlayer.
What I keep from it
Hide things and measure. The bisect took minutes once I had a port to run on, and it pointed at two objects I would not have guessed. The second lesson cost more: on software GL the shader is the price, not the texture, so “draw it once” has to mean once through something cheap. And a test that times out is telling you where the player stopped, not how long it took. I had the screenshot in that failure too. I read it days later.