Netcode: prediction and smoothing
15 to 16 Nov 2026
- The page now guesses an event only when no other ball can change it. A pop then shows one frame after the touch instead of 67 to 150 ms later, and about 120 pops were all guessed right.
- Your ball is now drawn on an even clock. It moves 2 to 2.5 times more steadily, and that costs 12 ms of extra drawn latency at p99.
- Half of the wobble in other balls comes from wrong guesses about their keys. Drawing them in the past instead made the wobble 2 to 6 times worse.
- A setting called Automatic replaced the fixed default. It switches to Light only when prediction takes 12% or more of the time.
Before tuning anything, build a harness that scores every drawn frame against the server. Most of the snaps were in our own drawing code.
The netcode uses client prediction with server reconciliation. The browser runs the same physics as the server, so your keys move your ball at once. When a snapshot from the server arrives, the page resets the world to the server’s state and replays the keys the server has not seen yet. This fits any fast game where the server must have the final word. The wiki page Netcode has the current design and every number.
Measured how: we ran the real room and the real page in one process, on a virtual clock, over a simulated link with 35, 80 and 150 ms of latency and 1 to 3% loss. The harness replayed the tick timing of live rooms and scored every drawn frame against the server. That harness later became the feel audit and the feel gate we run before each deploy.
Guess only what nothing else can change
First we let the server decide every event. That stopped the phantom events (from 2 to 0 over 11 runs), but within hours players felt the 67 to 150 ms wait. What worked was a narrower rule. The page guesses an event only when no other ball can change it, and it widens the margin by how uncertain the guess has been when measured.
| What | Before | After |
|---|
| Pops after the touch | 67 to 150 ms | One frame (17 ms); none wrong in about 120 |
| Bombs | Ball drawn stopped inside for 50 to 167 ms | 0 ms; about 3% of guesses undone |
| Neutral flag handover | 83 to 133 ms, up to 300 | 0 ms, at most 17 |
| Your ball through portals | 3 to 7 stutters per 5 trips | 0 |
| A key press applied a frame back in time | Other balls kinked 265 to 1,000 times a minute | 0 to 0.4 |
| Your ball’s step error at p99 (Classic netcode, 15 ms ping) | 10.0% | 2.9% (under 5% looks crisp) |
| Two balls drawn holding one flag | 169 to 300 frames a minute | 0 |
Harness runs, 15 and 16 Nov 2026. The full before and after tables are in the wiki: Netcode measurements.
The page draws your own ball from a ring of its last 32 steps. A clock runs at the tick rate and drifts slowly toward the page’s estimate of the server’s time. On live timing this made your ball 2 to 2.5 times steadier, and it added 12 ms of drawn latency at p99.
Other balls wobble for two reasons in equal parts. The page guesses their keys wrong, and corrections blend in. Drawing them in the past made the wobble 2 to 6 times worse, so the page still draws them where it guesses they are now.
There are three netcode modes. Classic applies your keys about half a ping later, as the classic game does. Instant applies them at once. Light runs no physics in the page, for slow computers. On 16 Nov a mode called Automatic replaced the fixed default and the one-time offer of Light. Automatic uses Classic and switches to Light only when prediction takes 12% or more of the time.
What didn’t work
- Running the server at 90 or 120 ticks a second: the jitter did not go down, and the cost went up 1.2 to 2 times.
- Holding a ball at a bomb, or two balls at an uncertain tag, until the server answers: throws got worse and there were more kinks.
- Rules that commit to guesses of other balls’ keys: the error halved at 150 ms, but the wobble rose 5 to 100%.
- One smooth tick timeline for everything: it caused 0 to 98 corrections a minute on a trace where the server jumps 6 to 10 ticks.
- The first version of skipping the replay: we turned it off within the hour, because the step error on a chain of portals rose from 2% to 66%.
- UDP: Workers cannot receive it, and the late updates came from stalled rooms, not from lost packets.
Reuse
- Build the harness first. Run the real server and client on a virtual clock and score every frame against the server.
- Guess an event only when no other actor can change it, and widen the margin by the guess’s own uncertainty.
- Draw the local player on an even clock fed from a history ring. Let corrections ease in, but never ease the speed.
All the numbers are in the wiki: Netcode measurements.