ReviewOS

stacks/the-settlers-iii-remake

Bound terrain cache memory and release retired canvas backing stores

#216
Closed chris opened this 7 days ago ·
7 days ago

Terrain chunks remain in the renderer cache after the camera leaves them. On an unchanged 800 by 480 viewport and a public 256 by 256 flat world, panning through four positions and returning retains 32 chunk canvases with 130,744,320 bytes of RGBA capacity, compared with 12 canvases and 49,152,000 bytes initially. The simulation checksum is unchanged. These numbers measure retained canvas dimensions, not total process RSS.

The reproduction uses the published renderer with one read-only diagnostic getter over the actual retained canvases. No browser API or allocation is replaced. Source inspection confirms that the chunk map has no eviction; replacing a stale chunk also drops its backing store without explicitly releasing it.

Acceptance:

  • Retain a real browser pan-and-return regression through public sessions and renderer calls.
  • Enforce an explicit byte budget independent of map size and camera history. Release evicted, replaced and cleared canvas backing stores.
  • Keep rendering complete when a viewport or a single chunk exceeds the retained cache budget. Do not reduce supported map sizes or relax allocation guards.
  • Verify stable pixels on return, repeated draws, fog/territory invalidation, asset replacement and disposal; preserve simulation state.
  • Document what the reported resource measurements cover and run complete checks and CI.

Source owner: game renderer. Related #20, #88 and #100. The separate terrain coverage problem remains independently tracked. This work establishes a terrain cache bound, not complete large-world performance or native host qualification.

7 days ago

The renderer now evicts terrain by retained byte capacity and explicitly releases retired canvas backing stores. The original pan sequence stays below 64 MiB; returning to the starting view produces identical pixels. Player and session changes also clear the correct sight cache.

The first bounded policy caused repeated rasterization in wide views. The corrected path uses a backing density appropriate to the displayed resolution and bounds chunks by their actual projected vertices. Repeated draws at the interface minimum zoom now rebuild no chunks. A larger view still paints correctly when its 81,920,000 bytes of drawn raster capacity exceed the retained budget.

Browser checks cover 26 draws, changing chunk heights, fog refresh, assets, palettes, disposal and simulation checksums. A separate exact comparison found zero channel differences at 100% zoom across flat ground, hills, cliffs and mixed terrain. Complete checks and CI qualification are next. Terrain mesh seams remain tracked in #215, and this does not qualify total process/GPU memory or native performance.

7 days ago

Terrain retention is now bounded to 64 MiB. Evicted, replaced and cleared canvases release their backing stores; cache ownership also respects the session and viewing player. Projected bounds and backing density avoid repeated rasterization at the interface minimum zoom.

The complete Linux CI run passed 388 unit tests, asset verification, types, lint, production build and 506 browser checks across 15 suites, including the full production-paced battle. Its original diagnostic archive was verified against the GitHub digest and ZIP checksums. All suites report no console errors or failed requests.

The cache fixture covers 26 draws, pan/return pixel stability, repeated minimum-zoom draws without rebuilding, a view whose raster capacity exceeds the retained budget, elevations, player/session switching, visibility, assets, palettes and disposal. The previous renderer fails the retained-capacity regression.

This completes the terrain-cache scope. The measurements describe backing-store capacity, not total process or GPU memory. Large-world/native frame-rate qualification remains #100, and terrain coverage seams remain #215.

Sign in to comment on this issue.