From ea7d5089b89d17bb72a4f6ef09cdea5683c9fc45 Mon Sep 17 00:00:00 2001 From: scamiv <6170744+scamiv@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:41:47 +0100 Subject: [PATCH] Size SAB ring buffer by world tile count --- src/client/ClientGameRunner.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/client/ClientGameRunner.ts b/src/client/ClientGameRunner.ts index d5b535500..09f1d21e7 100644 --- a/src/client/ClientGameRunner.ts +++ b/src/client/ClientGameRunner.ts @@ -190,10 +190,9 @@ async function createClientGame( const usesSharedTileState = !!sharedStateBuffer; if (canUseSharedBuffers) { - // Capacity is number of tile updates that can be queued. - // This is a compromise between memory usage and backlog tolerance. - const TILE_RING_CAPACITY = 262144; const numTiles = gameMap.gameMap.width() * gameMap.gameMap.height(); + // Ring capacity scales with world size: at most one entry per tile. + const TILE_RING_CAPACITY = numTiles; sharedTileRingBuffers = createSharedTileRingBuffers( TILE_RING_CAPACITY, numTiles, @@ -701,8 +700,8 @@ export class ClientGameRunner { uniqueTiles.add(ref); } - // Calculate ring buffer utilization and overflow - const TILE_RING_CAPACITY = 262144; + // Calculate ring buffer utilization and overflow using dynamic capacity + const TILE_RING_CAPACITY = this.tileRingViews.capacity; const utilization = (uniqueTiles.size / TILE_RING_CAPACITY) * 100; const overflow = Atomics.load( this.tileRingViews.header,