bug: tile loading wastes requests and never recovers 404s #86

Closed
opened 2026-11-21 21:38:53 +01:00 by SirStone · 1 comment
Owner

Part of #63

Symptom (owner, GM playtest)

GM at zoom 0.115 on a 16384 px scene with 64 px tiles: ~29k tiles in view, ~55k tile requests, minutes to fill. The client sits at TILE_CONCURRENCY = 8 (client/src/tiles.ts) while the server gate + nginx sustain ~2.5k/s, so the browser queue, not the server, is the bottleneck.

Diagnosis

  1. Request order is row-major (top-left first), so the first visible pixels are the corner, not the centre.
  2. client/src/render/modules/tiles.ts rebuilds the whole wanted array + Set on every settle: O(window) per tile, O(window^2) per fill.
  3. Concurrency is a fixed 8; no measurement of the browser decode/upload knee.
  4. Each failed tile costs 2 requests: <img> error carries no status, then a fetch re-asks for 403 vs 404/5xx.
  5. A 404/5xx is stored forever (tiles.ts, denied for both 403 and 404) and never retried; the tile stays black until a page reload. A tile imported after the page loaded is never picked up.
  6. viewport.setScene silently replaces a same-id scene without emitting. A new art_version (re-import) changes every URL but the tile layer is never told and keeps the old textures.
  7. Versioned tile URLs (v<art_version>) are immutable but only sent Cache-Control: private, so every reload revalidates all of them.

Scope

Client + minimal server/nginx cache header; no LOD and no zoom-clamp change (owner decision pending). Design-neutral: same tile grid, same gate, same disclosure rules.

Fix (this issue)

  1. Centre-out request order (nearest the viewport centre first); queued tiles that leave the window are dropped (already the scheduler's rule).
  2. Incremental settle path: a settle touches only its tile (sprite + readiness), no full wanted rebuild.
  3. Raise TILE_CONCURRENCY to a measured knee (measure on Full HD at GM fit and player 0.5; the concurrent cap stays bounded).
  4. One request per tile: fetch -> createImageBitmap (status known, decode off the main thread), so a failure costs one request and gets its status directly.
  5. 403 stays permanent (retried only on fog.fresh); 404/5xx/network become transient: up to 3 loads with exponential backoff, and retryFailed() on hello/reconnect and on scene/art_version change. viewport.setScene emits for a same-id scene so an art_version change drops the texture cache and refetches.
  6. Tiles sent as Cache-Control: private, max-age=31536000, immutable (still gated); DESIGN 3.3/11.1 updated.

Acceptance

  • Vitest: centre-out order; incremental sync (settle does not rebuild the window); retry policy (backoff, bounded, reconnect resets); art_version change drops the cache; same-scene setScene emits.
  • e2e: GM survey zoom on a Full HD scene reaches ready with one request per tile; a 404 tile is retried a bounded number of times and recovers after the file appears + reconnect.
  • Before/after numbers recorded (min-of-3, headless, GM fit and player 0.5 on 1920x1080 at tile 32 and 64).
  • Full gate green (devbox run test, client-test, e2e); issue closed with the numbers.

Note: map images are being capped at Full HD by a separate ticket; the 16384 measurement is therefore not repeated here. The warning about huge survey fills is that ticket's docs change, not this one.

#77 is blocked by this.

Part of #63 ## Symptom (owner, GM playtest) GM at zoom 0.115 on a 16384 px scene with 64 px tiles: ~29k tiles in view, ~55k tile requests, minutes to fill. The client sits at `TILE_CONCURRENCY = 8` (client/src/tiles.ts) while the server gate + nginx sustain ~2.5k/s, so the browser queue, not the server, is the bottleneck. ## Diagnosis 1. Request order is row-major (top-left first), so the first visible pixels are the corner, not the centre. 2. `client/src/render/modules/tiles.ts` rebuilds the whole wanted array + Set on every settle: O(window) per tile, O(window^2) per fill. 3. Concurrency is a fixed 8; no measurement of the browser decode/upload knee. 4. Each failed tile costs 2 requests: `<img>` error carries no status, then a `fetch` re-asks for 403 vs 404/5xx. 5. A 404/5xx is stored forever (`tiles.ts`, `denied` for both 403 and 404) and never retried; the tile stays black until a page reload. A tile imported after the page loaded is never picked up. 6. `viewport.setScene` silently replaces a same-id scene without emitting. A new `art_version` (re-import) changes every URL but the tile layer is never told and keeps the old textures. 7. Versioned tile URLs (`v<art_version>`) are immutable but only sent `Cache-Control: private`, so every reload revalidates all of them. ## Scope Client + minimal server/nginx cache header; **no LOD and no zoom-clamp change** (owner decision pending). Design-neutral: same tile grid, same gate, same disclosure rules. ## Fix (this issue) 1. Centre-out request order (nearest the viewport centre first); queued tiles that leave the window are dropped (already the scheduler's rule). 2. Incremental settle path: a settle touches only its tile (sprite + readiness), no full wanted rebuild. 3. Raise `TILE_CONCURRENCY` to a measured knee (measure on Full HD at GM fit and player 0.5; the concurrent cap stays bounded). 4. One request per tile: `fetch` -> `createImageBitmap` (status known, decode off the main thread), so a failure costs one request and gets its status directly. 5. 403 stays permanent (retried only on `fog.fresh`); 404/5xx/network become transient: up to 3 loads with exponential backoff, and `retryFailed()` on `hello`/reconnect and on scene/art_version change. `viewport.setScene` emits for a same-id scene so an `art_version` change drops the texture cache and refetches. 6. Tiles sent as `Cache-Control: private, max-age=31536000, immutable` (still gated); DESIGN 3.3/11.1 updated. ## Acceptance - [ ] Vitest: centre-out order; incremental sync (settle does not rebuild the window); retry policy (backoff, bounded, reconnect resets); art_version change drops the cache; same-scene `setScene` emits. - [ ] e2e: GM survey zoom on a Full HD scene reaches `ready` with one request per tile; a 404 tile is retried a bounded number of times and recovers after the file appears + reconnect. - [ ] Before/after numbers recorded (min-of-3, headless, GM fit and player 0.5 on 1920x1080 at tile 32 and 64). - [ ] Full gate green (`devbox run test`, `client-test`, `e2e`); issue closed with the numbers. Note: map images are being capped at Full HD by a separate ticket; the 16384 measurement is therefore not repeated here. The warning about huge survey fills is that ticket's docs change, not this one. #77 is blocked by this.
SirStone added the ready-for-agentbug labels 2026-11-21 21:38:53 +01:00
SirStone added a new dependency 2026-11-21 21:38:59 +01:00
Author
Owner

Fixed in 52ab50d (pushed to main).

What landed

  • Centre-out request ordering (orderTilesCentreOut); queued tiles that leave the window are dropped.
  • Incremental settle path: one settle touches one tile (sprite + readiness); the wanted window is rebuilt only on camera/scene changes (was O(window) per tile).
  • TILE_CONCURRENCY 8 -> 32 (measured knee, see below).
  • One request per tile: fetch + createImageBitmap, so 403 vs 404/5xx comes from the same response (was <img> + a second fetch on every failure).
  • 403 still permanent (retried only on fog.fresh). 404/5xx/network now transient: up to 3 loads with 250/500 ms backoff; hello/reconnect and a scene/art_version change reset the budget. A failure settling after a reconnect is a fresh first attempt; a load that left the window does not spend the budget.
  • viewport.setScene emits for a same-id scene, and a new art_version drops the texture cache and refetches.
  • Tiles now Cache-Control: private, max-age=31536000, immutable (still gated); DESIGN 3.3/11.1 and client/README updated.

Numbers (owner scope change: map capped at Full HD, so measured 1920x1080 at tile 32 and 64; no 16384 run). Same repro method (headless Chromium, SwiftShader, page load -> wheel to fit / 0.5 -> data-tiles=ready, min-of-3, interleaved A/B on a saturated host):

case before after
GM fit, tile 32 (2040 tiles) 910 ms 843 ms
player 0.5, tile 32 (2040) 972 ms 862 ms
GM fit, tile 64 (510) 320 ms 249 ms
player 0.5, tile 64 (510) 332 ms 368 ms (inside host noise)

At Full HD the wall-clock win is small; the load-bearing wins are correctness: a 404 no longer leaves a permanent black tile, a failure costs one request instead of two, an art_version change refetches, and the reload revalidates no tile URLs.

Tests: vitest for centre-out order, incremental invariants, retry budget/backoff, reconnect epoch, art_version invalidation, same-scene setScene emit; e2e for GM survey fill (one request per succeeded tile, 2040 distinct) and 404 recovery after the file appears + a real reconnect (server restart, fresh hello). Full gate green before push: devbox run test, client-test, e2e.

#77 now has one fewer blocker (and remains blocked by the others).

Fixed in 52ab50d (pushed to main). **What landed** - Centre-out request ordering (`orderTilesCentreOut`); queued tiles that leave the window are dropped. - Incremental settle path: one settle touches one tile (sprite + readiness); the wanted window is rebuilt only on camera/scene changes (was O(window) per tile). - `TILE_CONCURRENCY` 8 -> 32 (measured knee, see below). - One request per tile: `fetch` + `createImageBitmap`, so 403 vs 404/5xx comes from the same response (was `<img>` + a second `fetch` on every failure). - 403 still permanent (retried only on `fog.fresh`). 404/5xx/network now transient: up to 3 loads with 250/500 ms backoff; `hello`/reconnect and a scene/`art_version` change reset the budget. A failure settling after a reconnect is a fresh first attempt; a load that left the window does not spend the budget. - `viewport.setScene` emits for a same-id scene, and a new `art_version` drops the texture cache and refetches. - Tiles now `Cache-Control: private, max-age=31536000, immutable` (still gated); DESIGN 3.3/11.1 and client/README updated. **Numbers** (owner scope change: map capped at Full HD, so measured 1920x1080 at tile 32 and 64; no 16384 run). Same repro method (headless Chromium, SwiftShader, page load -> wheel to fit / 0.5 -> `data-tiles=ready`, min-of-3, interleaved A/B on a saturated host): | case | before | after | |---|---|---| | GM fit, tile 32 (2040 tiles) | 910 ms | 843 ms | | player 0.5, tile 32 (2040) | 972 ms | 862 ms | | GM fit, tile 64 (510) | 320 ms | 249 ms | | player 0.5, tile 64 (510) | 332 ms | 368 ms (inside host noise) | At Full HD the wall-clock win is small; the load-bearing wins are correctness: a 404 no longer leaves a permanent black tile, a failure costs one request instead of two, an `art_version` change refetches, and the reload revalidates no tile URLs. **Tests**: vitest for centre-out order, incremental invariants, retry budget/backoff, reconnect epoch, `art_version` invalidation, same-scene `setScene` emit; e2e for GM survey fill (one request per succeeded tile, 2040 distinct) and 404 recovery after the file appears + a real reconnect (server restart, fresh `hello`). Full gate green before push: `devbox run test`, `client-test`, `e2e`. #77 now has one fewer blocker (and remains blocked by the others).
Sign in to join this conversation.