feat(m4): cap map images at Full HD and shrink on import (#85)

The owner fixed the map cap at 1920 px on the long side and 1080 px on the
short side (either orientation). fff-vtt import now shrinks a larger source
with ImageMagick Lanczos before tiling (alpha kept, proportions preserved,
no upscaling), prints `scaled WxH -> WxH`, and records the shrunk w/h; a
source at or below the cap is untouched, so the pixel-identity tests still
hold. A scene row already above the cap is not rewritten: the server logs
`map_above_cap` at startup and serve prints the re-import advice.

Docs: ADR-0023, DESIGN 3.3/5.3/8/11.1/13/14, TESTING 5.3/13, README,
HANDOFF-M4, client README. The M4 phone gate and the fogbench measurement
now use the Full HD maximum; the 16384 px / 262144-cell bench and test rows
stay as labelled server stress references. import-scale now proves a 16384²
input is shrunk to 1080x1080 (289 tiles at 64 px) quickly and bounded.

Part of #63, #85. #77 is blocked by this issue.
This commit is contained in:
2026-11-21 22:16:08 +01:00
parent 30b35592c7
commit 43947d1197
22 changed files with 515 additions and 193 deletions
+22 -22
View File
@@ -1,25 +1,25 @@
== prototype scene (60 walls, 8 tokens, radius 400, cell 32) ==
1 poly (jittered start positions): n=2000 avg=0.013ms worst=0.075ms
6 polys (one 6-token party): n=500 avg=0.074ms worst=0.123ms
1 poly + cellsTouched (scanline): n=2000 avg=0.019ms worst=0.072ms
6 polys + cellsTouched (scanline): n=300 avg=0.172ms worst=0.252ms
1 poly + cellsTouchedOld (prototype reference): n=500 avg=0.685ms worst=2.616ms
TARGET polygon+cells, prototype scene (prototype baseline 0.451): 0.019 ms vs <= 0.451 ms: PASS
== 5k sparse: genScene(world=16384., n=5000, seed=1), avg walls in vision bbox 15.6 ==
1 poly, 5k sparse: n=2000 avg=0.035ms worst=0.433ms
1 poly + cellsTouched, 5k sparse: n=2000 avg=0.047ms worst=0.451ms
1 move check (pathClear, cap-length step), 5k sparse: n=20000 avg=0.007ms worst=0.466ms
TARGET polygon, 5k-wall scene: 0.035 ms vs <= 1.0 ms: PASS
== 5k dense: genScene(world=4096., n=5000, seed=1), avg walls in vision bbox 206.9 ==
1 poly, 5k dense: n=2000 avg=0.747ms worst=1.900ms
1 poly + cellsTouched, 5k dense: n=2000 avg=0.811ms worst=1.614ms
1 move check (pathClear, cap-length step), 5k dense: n=20000 avg=0.008ms worst=0.042ms
== egress (#28: 6 players x 40 encountered entries, 262144 explored cells) ==
GM egress pass (fresh diff base): n=200 avg=0.423ms worst=1.106ms
player egress pass (fresh diff base): n=200 avg=0.109ms worst=0.214ms
1 poly (jittered start positions): n=2000 avg=0.020ms worst=0.873ms
6 polys (one 6-token party): n=500 avg=0.160ms worst=7.235ms
1 poly + cellsTouched (scanline): n=2000 avg=0.034ms worst=1.181ms
6 polys + cellsTouched (scanline): n=300 avg=0.187ms worst=0.349ms
1 poly + cellsTouchedOld (prototype reference): n=500 avg=0.849ms worst=2.251ms
TARGET polygon+cells, prototype scene (prototype baseline 0.451): 0.034 ms vs <= 0.451 ms: PASS
== 5k sparse (stress): genScene(world=16384., n=5000, seed=1), avg walls in vision bbox 15.6 ==
1 poly, 5k sparse (stress): n=2000 avg=0.058ms worst=0.197ms
1 poly + cellsTouched, 5k sparse (stress): n=2000 avg=0.061ms worst=0.169ms
1 move check (pathClear, cap-length step), 5k sparse (stress): n=20000 avg=0.009ms worst=0.245ms
TARGET polygon, 5k-wall stress scene: 0.058 ms vs <= 1.0 ms: PASS
== 5k dense (stress): genScene(world=4096., n=5000, seed=1), avg walls in vision bbox 206.9 ==
1 poly, 5k dense (stress): n=2000 avg=1.409ms worst=17.788ms
1 poly + cellsTouched, 5k dense (stress): n=2000 avg=1.712ms worst=16.250ms
1 move check (pathClear, cap-length step), 5k dense (stress): n=20000 avg=0.013ms worst=4.333ms
== egress (#28 stress: 6 players x 40 encountered entries, 262144 explored cells) ==
GM egress pass (fresh diff base): n=200 avg=0.586ms worst=1.199ms
player egress pass (fresh diff base): n=200 avg=0.188ms worst=2.470ms
== tile gate (#65): old SQL-under-lock path vs published snapshot ==
tile gate old: parse + SHA-256 + session JOIN + HashSet: n=2000 avg=0.012ms worst=0.023ms
tile gate new: parse + SHA-256 + cache lookup + bitmap: n=2000 avg=0.002ms worst=0.024ms
explored snapshot build (262144 cells): n=20 avg=3.472ms worst=3.852ms
explored incremental mark (16 fresh cells): n=5000 avg=0.001ms worst=0.011ms
tile gate old: parse + SHA-256 + session JOIN + HashSet: n=2000 avg=0.014ms worst=0.582ms
tile gate new: parse + SHA-256 + cache lookup + bitmap: n=2000 avg=0.001ms worst=0.013ms
explored snapshot build (262144 cells): n=20 avg=3.606ms worst=4.623ms
explored incremental mark (16 fresh cells): n=5000 avg=0.002ms worst=0.765ms
(sink 24393102)
+3 -3
View File
@@ -1,5 +1,5 @@
# scale: gen=2515ms import=15259ms peakRSS=486MiB peakFds=71 peakProcs=10 tiles=65536
✔ map import CLI: 16384 px source at 64 px stays memory- and fd-bounded (#83) (21279.293203ms)
# scale: gen=5279ms import=12558ms peakRSS=303MiB peakFds=65 peakProcs=10 tiles=289
✔ map import CLI: a 16384 px source is shrunk to Full HD and stays memory- and fd-bounded (#83, #85) (21653.434682ms)
ℹ tests 1
ℹ suites 0
ℹ pass 1
@@ -7,4 +7,4 @@
ℹ cancelled 0
ℹ skipped 0
ℹ todo 0
ℹ duration_ms 21545.730115
ℹ duration_ms 22009.487202
+6 -8
View File
@@ -1,10 +1,8 @@
/home/davide/Projects/GDR/FFF_vtt-m76/server/worldmap.nim(18, 44) Warning: imported and not used: 'faults' [UnusedImport]
/home/davide/Projects/GDR/FFF_vtt-m76/server/vision.nim(31, 43) Warning: imported and not used: 'faults' [UnusedImport]
== M4 fog bench: 16384 px map, cell 32 (512x512 cells), 50 tokens, 4979 walls ==
server vision refresh, one player (1 polygon, radius 300, ~5k walls): n=500 avg=0.054ms worst=0.132ms
== M4 fog bench: Full HD map 1920x1080, cell 32 (60x34 cells), 50 tokens, 1875 walls ==
server vision refresh, one player (1 polygon, radius 300, 5k-wall generator clipped to the scene): n=500 avg=0.055ms worst=0.448ms
player egress frames with 50 visible tokens: 52 frames, "vision","explored","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token","token"
player egress pass, 50 visible tokens (fresh Known): n=300 avg=0.089ms worst=0.167ms
player egress pass, warm Known (no changes): n=2000 avg=0.094ms worst=0.261ms
explored snapshot size: 316 cells on the 16384 px map
TARGET move path: refresh + 50-token egress 0.143 ms vs <= 16.7 ms (one 60 fps frame): PASS
player egress pass, 50 visible tokens (fresh Known): n=300 avg=0.201ms worst=1.673ms
player egress pass, warm Known (no changes): n=2000 avg=0.187ms worst=2.278ms
explored snapshot size: 318 cells on the Full HD map
TARGET move path: refresh + 50-token egress 0.256 ms vs <= 16.7 ms (one 60 fps frame): PASS
(sink 20800)
+22 -17
View File
@@ -1,52 +1,57 @@
# M4 fog measurement: 50 tokens on a 16384 px map (#76)
# M4 fog measurement: 50 tokens on a Full HD map (#76, #85)
Recorded 2026-11-21 on the M4 finish tree. Command: `devbox run fogbench` (server half,
`tools/fogbench.nim`, raw log `results/m4-fog-bench.log`) and
`client/e2e/fogbench.test.mjs` (headless client half, `devbox run e2e`).
The scene is the **Full HD maximum** (1920x1080), the owner's cap of 2026-11-21 (#85, ADR-0023);
the old 16384 px map is no longer the product target.
The question this answers (spec #63, Testing notes): **does M4 need the per-token polygon cache
(build item 3) or incremental wall-edit refresh (build item 4) before the phone run?** The answer is
no: the measured move path is two orders of magnitude inside one 60 fps frame.
## Server recompute (real modules, release build)
Scene: 16384 x 16384 px, cell 32 (512 x 512 cells = 262 144), 4 979 sparse walls
(`genScene(16384, 5000, 1)` with the 50-token cluster box cleared), 50 tokens, one controlled token
with `vision` and radius 300. This is what `main.refreshPlayer` runs for one `token.move`, plus the
egress that follows it for that player.
Scene: 1920 x 1080 px, cell 32 (60 x 34 cells = 2 040), 1 875 walls (the 5k-wall generator clipped to
the Full HD height, with the 50-token cluster box cleared), 50 tokens, one controlled token with
`vision` and radius 300. This is what `main.refreshPlayer` runs for one `token.move`, plus the egress
that follows it for that player.
| Measurement | n | avg | worst |
|---|---:|---:|---:|
| vision refresh: polygon + `cellsTouched` + explored fold (1 token, 5k walls) | 500 | **0.044-0.054 ms** | 0.132 ms |
| player egress, 50 visible tokens (`token` frames, fresh `Known` = reconnect) | 300 | **0.075-0.089 ms** | 0.167 ms |
| player egress, warm `Known` (no changes) | 2000 | 0.084-0.094 ms | 0.261 ms |
| move path total (refresh + 50-token egress) | | **0.119-0.143 ms** | |
| vision refresh: polygon + `cellsTouched` + explored fold (1 token, 1875 walls) | 500 | **0.055 ms** | 0.448 ms |
| player egress, 50 visible tokens (`token` frames, fresh `Known` = reconnect) | 300 | **0.201 ms** | 1.673 ms |
| player egress, warm `Known` (no changes) | 2000 | 0.187 ms | 2.278 ms |
| move path total (refresh + 50-token egress) | | **0.256 ms** | |
(Brackets are run-to-run spread across the finish runs; the raw last run is in
`results/m4-fog-bench.log`.)
Budget: one 60 fps frame is 16.7 ms. The move path uses ~1 % of it. Cached per-token polygons
would save ~0.05 ms while adding an invalidation surface; **not built** (ticket AC: no
polygon-cache work unless the measurement says so). `results/bench.log` holds the M1-M3 baselines
(polygon 0.041 ms sparse, 0.73 ms dense 5k) and the explored/tile-gate numbers.
polygon-cache work unless the measurement says so). `results/bench.log` holds the current server
baselines (polygon 0.058 ms on the 5k sparse stress scene, 1.409 ms on the 5k dense stress scene)
and the explored/tile-gate numbers.
## Headless client frame cadence (correctness floor only)
Scene: the real server on the prepared 16384 px scene (scene row patched before boot; only the M6
Scene: the real server on the prepared Full HD scene (scene row patched before boot; only the
importer owns `w`/`h`), 50 tokens inside the sight, fog active, first viewport filled. Emulation:
412 x 869 CSS px, DPR 2.625, touch, mobile, then CDP 4x CPU throttle for the second sample.
| Measurement | value |
|---|---:|
| fog explored snapshot at connect (512 x 512 cells) | **2.0-2.2 ms** |
| explored cells in the sight | 540 |
| rAF cadence, real CPU (120 frames) | median **70-78 ms**, p95 81-166 ms |
| rAF cadence, 4x CPU (90 frames) | median **77-83 ms**, p95 83-167 ms |
| fog explored snapshot at connect (60 x 34 cells) | **0.7 ms** |
| explored cells in the sight | 542 |
| rAF cadence, real CPU (120 frames) | median **89.2 ms**, p95 182.2 ms |
| rAF cadence, 4x CPU (90 frames) | median **100.7 ms**, p95 213.1 ms |
**These are SwiftShader numbers, not phone numbers.** Headless Chromium in this repo renders with
the software rasteriser (no GPU), so its cadence is a floor for correctness and regression work. It
is deliberately **not a gate** (spec #63: no timing gate in the client suite). The 4096 px/50-token
run in `client/e2e/fog.test.mjs` records the same order (median 72-98 ms) and is also recorded only.
run in `client/e2e/fog.test.mjs` is a synthetic stress fixture (above the product cap) and its
cadence is also recorded only.
The real 60 fps pass on the Note 10 and the laptop is **#77** and is the authority for the M4 accept.
## What was not measured here