Rendering and netcode ideas we dropped
16 to 20 Nov 2026
- A WebGL2 layer for trails, ball bodies and particles never beat batching them on the 2D canvas. Copying its picture into the game’s canvas alone cost 0.6 to 0.8 ms of script at p95 at 4x CPU, past the 0.3 ms limit we had set.
- Garbage collection was not the lag. Over 60 s at 4x CPU the longest collection took 17 to 20 ms, no frame took over 33 ms, and the cheap fixes cut about 1% of the garbage.
- On slow computers, snapshots piled up after one long frame. Replaying only the newest one while frames are slow took frames over 50 ms in 3 minutes from 807 and 809 to 17 and 33 at 6x CPU.
- Without a GPU the backdrop was the cost. Drawing it plain took the main thread from 967 to 400 ms a second, and shrinking the canvas made the compositor about 4 times busier.
- Drawing other balls in the past made their wobble 2 to 6 times worse, and committing to guesses of their keys raised it 5 to 100%.
Each was measured beside the cheaper option on the same frames. Batching on the 2D canvas did as well as WebGL wherever WebGL helped at all.
From 16 to 20 Nov we measured these drawing and netcode changes, then dropped them or kept less. Timings come from one shared Mac running other jobs (1-minute load 18 to 82), so read the milliseconds as comparisons inside one run.
A WebGL layer for balls, trails and particles
We drew trails, ball bodies and particles, the parts that grow with the player count, in one WebGL2 instanced draw, and copied that picture into the game’s 2D canvas with one drawImage. We set a limit first: stop if the copy alone costs over 0.3 ms a frame at 4x CPU. Measured on recorded Sandbox games replayed at 1440 by 900, every ball copied 1 to 16 times, the GPU on and off, all ways interleaved in one page.
| Balls | Batching on the 2D canvas | WebGL |
|---|
| As today | -0.04 GPU, -0.43 main | +0.37 GPU, -0.45 main |
| 4 times | -0.12 GPU, -0.91 main | +0.16 GPU, -0.80 main |
| 8 to 16 times | -0.44 GPU, -1.93 main | -0.16 GPU, -2.26 main |
ms a frame at 4x CPU against today’s drawing; negative is cheaper. Load 26 to 62.
The copy alone cost 0.6 to 0.8 ms of script at p95, past the limit. WebGL paid only from about 50 ball bodies or 1,700 trail pieces in view, 8 to 16 times today’s busiest scenes, and batching did as well at counts real games reach. Without a GPU the copy is a readback: 4 to 31 ms a frame at 1x CPU.
On 16 Nov, drawing the map’s moving pieces from cached pictures cut their canvas calls from 639 to 242 a frame and saved no measurable frame time (load 31 to 46).
Ruled out without building:
- Pixi or three.js: the Play page’s first download had 20 to 22 KB to spare under its 1,320 KB budget (library sizes not measured).
- A second stacked canvas: it breaks frame sync with the low-latency canvas and drops a layer from clips.
- Drawing in a worker with OffscreenCanvas: the frame’s input holds functions, and it adds a frame (16.7 ms at 60 Hz) unless prediction moves too.
Next is batching on the 2D canvas, trails first (not built yet): in this test it cut the trails’ script by about half from 4 times the balls.
Garbage collection as the cause of lag
A performance audit had named 60 to 70 ms collection pauses as a cause of lag, so we cut the garbage each frame makes. Measured on a busy Sandbox 4 v 4 traced for 60 s at 4x CPU (load 27 to 52).
The pauses did not show up. The longest major collection took 17 to 20 ms and no frame took over 33 ms. The page makes 84 to 98 KB of garbage a frame. The safe fixes took about 1 KB of it, 1%, and collections stayed within the run-to-run spread. The fixes stay on.
What the lag on slow computers was
Measured on an online 4 v 4 with a 60 ms round trip, at 4x and 6x CPU and with the GPU off, runs compared side by side (load 27 to 81).
Snapshots piled up. After one long frame the page replayed 2 to 5 snapshots back to back, which made the next frame long too. At 6x CPU the snapshot handler took 412 ms of every second. Now, while frames are slow, it replays only the newest snapshot once a frame. At 6x with Classic netcode, frames over 50 ms in 3 minutes fell from 809 and 807 to 17 and 33. An earlier version also held snapshots back between fast frames; the feel gate failed it (other balls’ error at pickups on one map rose from 0 to 31.6 px).
Without a GPU, two full-canvas fills of the backdrop made 90% of the canvas work. Shrinking the canvas was a poor first step, because the browser then stretches it in software each frame.
| Software canvas, one step | fps | Main thread | Compositor |
|---|
| None | 49.9 | 967 | 208 |
| Plain backdrop | 59.3 | 400 | 152 |
| 85% size | 50.7 | 953 | 745 |
| 75% size | 59.0 | 764 | 565 |
CPU ms a second at 1920 by 1080. Load 27 to 82.
Auto quality now turns on the plain backdrop first on a software canvas and tries smaller sizes last.
Smoothing other balls
Other balls wobble because the page guesses their next keys. Stepped on the keys really pressed, they wobbled only 12 to 49 times a minute. On 16 Nov we tried three fixes (4 v 4 bots, live room timing):
- Committing to a key guess. Error at p50 halved at 150 ms, but wobble rose 5 to 100%.
- A slower correction blend. Wobble fell 40 to 68%, but other balls’ error at p99 went over the test’s limit at 30, 60 and 150 ms.
- Drawing them half or one snapshot behind. Wobble was 2 to 6 times worse, and touches were drawn 2.5 to 15 px apart at p95 against 0.5 to 3.6. The feel gate read 14 and 17 rows worse.
Instead the page keeps guessing from their average push, and a small correction swings a ball at most twice its push, which cut wobble 3 to 11%. More in Netcode.
Prediction in a Web Worker
At 4x CPU prediction took 0.83 ms, 5% of a frame, under our 20% bar, and a worker’s answer comes a frame late. Not built.