Rooms on Cloudflare Durable Objects
15 to 16 Nov 2026
- With no bots in the room, the game clock still fell 40 to 94 ms behind real time. The room’s own code used only 5.5 ms of every 250 ms, so the delay came from Cloudflare’s platform, not from our code.
- We now limit the bots’ searches by the amount of work instead of by time. Expert bots then fit rooms of up to 8 bots. Their worst window was 12.8 ms, under the limit of 13.3 ms.
- Bots now think in their own object. The room’s step at p50 fell from 0.76 to 0.38 ms.
- A tick with 8 people fell from 0.050 to 0.040 ms, and the garbage made per tick fell from 26 to 11 KB.
A Durable Object’s clock stops while it works. Budget the work in each 250 ms window and bound it in a way that repeats exactly, or give real-time rooms a real clock.
Each game room ran as one Durable Object. That is single-threaded JavaScript on Cloudflare’s shared machines, running 60 ticks a second, with no server size to pick. This suits any small real-time room server that should need no operations work. The catch is time. A Durable Object’s clock only moves forward when it does I/O. After a long piece of work, the clock reads behind real time, and every update is late until the room catches up. The wiki page A game tick describes how a tick works today.
Measured how: we ran staging rooms with scripted players on the live wire format. We also ran Node profiles with a fixed seed, so a run repeats exactly and a hash proves that a change sends the same bytes. We measured bot cost as thread CPU summed over 250 ms windows (the time between pings), and took the lowest of 3 runs. The Mac running the tests was shared, at a load of 7.7 to 35.
One limit appears below. A bot level fits a room if its worst 250 ms of CPU in Node, times 3, stays under 40 ms, because that is where the clock starts to fall behind on Cloudflare (which runs this code 3 to 4 times slower than Node). That limit is 13.3 ms in Node.
| Measured | Before | After |
|---|
| Times the room clock fell behind, staging, no bots | | 3 to 4 a minute, by 40 to 94 ms. The room’s own work was 5.5 ms per 250 ms, so the cause is the platform |
| Ticks behind real time at p50 / p99, live (with the clock catch-up fix) | 55 / 195 ms | 31 / 81 ms |
| Bot think time after an event (searches that could not change the answer removed) | 0.52 ms | 0.29 ms, every decision identical |
| Expert bots under the 13.3 ms limit (searches bounded by work) | 1 | up to 8 (12.8 ms) |
| Room step at p50 with 8 Expert bots (bots in their own object) | 0.76 ms | 0.38 ms |
| A tick of 8 people / garbage per tick | 0.050 ms / 26 KB | 0.040 ms / 11 KB |
Every table behind these numbers is in the wiki: Server and room measurements.
In a fresh process, an Expert bot’s first game on a map cost 2 to 5 times as much as its later games. Caches were not the cause. V8 threw the search code out of its optimized form the first time a game took a branch it had not seen before. We fixed it by limiting how many searches a bot runs per think, counted in work rather than in time. Every game still replays exactly.
What didn’t work
- A strict thinking budget per room: it gave fewer heavy windows, but the bots using it won only 40% ± 12 of 60 ladder games.
- Spreading the bots’ thinking over fixed phases: a 250 ms window holds the same amount of thinking either way.
- Warming up a map by playing an offscreen Expert game during the countdown: it helped only with 1 or 2 bots, and the warm-up itself cost 47 to 75 ms.
- Splitting the juke search over two thinks: those bots won 46.3% ± 5.1 of 360 games.
- The first version of the bounded search: a bomb was shown and then taken back after a ball grazed it by 0.0002 tiles. We reverted it until the page’s guesses used a 0.1-tile margin.
What replaced the Durable Object for competitive US West games is a box with a real clock (Servers: sockets, pauses, capacity). We also prepared Cloudflare Containers as another option, and they stay off.
Reuse
- On a platform whose clock stops while code runs, measure lateness per 250 ms window, not per tick, and repay the catch-up slowly.
- Bound expensive searches by work, not by time. Then games replay identically, and a hash can prove it.
- Measure the cost of the first game in a fresh process. JIT de-optimization was the main cost there, not caches.
All the numbers are in the wiki: Server and room measurements.