fix(client): tile loading: centre-out, one request per tile, 404 recovery (#86)
The GM survey view asked row-major, at most 8 at a time, rebuilt the whole wanted window on every settle, and paid two requests for every failed tile (image error, then a fetch to learn the status). A 404/5xx was stored as permanent `denied`, so a tile imported after page load stayed black until a page reload, and `viewport.setScene` swallowed a same-id art_version change so the old textures were never dropped. - TILE_CONCURRENCY 8 -> 32, the measured knee on a Full HD scene (min-of-3 headless: GM fit + player 0.5, tile 32/64; 64 is inside the noise). - orderTilesCentreOut: nearest the viewport centre first. - Settle path is incremental (one settle = one tile sprite/flag update); the window is rebuilt only on camera/scene changes. - fetch + createImageBitmap: status from the same response, decode off the main thread, so a failure costs one request. - 403 stays permanent (retried only on fog.fresh); 404/5xx/network retry with 250/500 ms backoff up to 3 loads, and `hello`/reconnect or a scene/art_version change resets the budget. A failure that lands after a reconnect is a fresh first attempt; a failure that leaves the window does not spend the budget. - setScene emits for a same-id scene; a new art_version drops the texture cache and reschedules. Tiles are `Cache-Control: private, max-age=1y, immutable` (still gated), so a reload reuses them; DESIGN 3.3/11.1 and client/README updated. Tests: vitest for ordering, incremental invariants, retry budget/backoff, reconnect epoch and art_version invalidation; e2e for a GM survey fill (one request per succeeded tile) and a 404 tile recovering after the file appears and a real reconnect. Before -> after (min-of-3, saturated host, Full HD): GM fit 32px 910->843 ms, player 0.5 32px 972->862 ms, GM fit 64px 320->249 ms, player 0.5 64px 332->368 ms (noise). Part of #63. Blocks #77.
This commit is contained in:
@@ -210,7 +210,9 @@ test('tile gate: leak check (d) matches the independent explored oracle', async
|
||||
const want = fs.readFileSync(path.join(tileDir(stateDir, scene.id, ctx.artVersion), `${x}_${y}.png`))
|
||||
if (!body.equals(want)) fail('served bytes are not the requested tile')
|
||||
if (r.headers.get('x-accel-redirect') !== null) fail('X-Accel-Redirect leaked to the client')
|
||||
if ((r.headers.get('cache-control') ?? '') !== 'private') fail('Cache-Control is not private')
|
||||
if ((r.headers.get('cache-control') ?? '') !== 'private, max-age=31536000, immutable') {
|
||||
fail('Cache-Control is not private + immutable')
|
||||
}
|
||||
} else if (r.status === 403) {
|
||||
if (vis.sure) fail('refused although the oracle is sure the cell is visible')
|
||||
if (vis.maybe) maybeRefused++
|
||||
@@ -340,7 +342,7 @@ test('tile gate: refusals, direct /_tiles, malformed and out-of-range paths', as
|
||||
const gate = await getTile(s.origin, ok, ctx.seenCtx.cookie)
|
||||
assert.equal(gate.status, 200)
|
||||
assert.equal(gate.headers.get('x-accel-redirect'), `/_tiles/${scene.id}/v${ctx.artVersion}/9_9.png`)
|
||||
assert.equal(gate.headers.get('cache-control'), 'private')
|
||||
assert.equal(gate.headers.get('cache-control'), 'private, max-age=31536000, immutable')
|
||||
assert.equal((await gate.text()), '', 'Nim sends the decision, not the bytes')
|
||||
const refused = await getTile(s.origin, unseen, ctx.seenCtx.cookie)
|
||||
assert.equal(refused.status, 403)
|
||||
|
||||
Reference in New Issue
Block a user