Files
airdef/airdef-mod
chexit dc87c0b98a sim: bound the ground cache and the recording under the 64 MiB WASM budget
The fullscreen-map OOM (rust_oom in hashbrown reserve_rehash under
Ground::answer during a large raid): the mod's whole state shares one
64 MiB linear memory, and three consumers grew without an effective bound.

Measured on a native replica of the crash load (tests/ground_oom.rs: 64
complexes, six all-sides Oreshnik raids plus a smart raid over 10000 ticks,
304 objects airborne at once, a wide map query walk; render answers exactly
as the WASM host gives them): peak 45.5 MiB steady + 21.9 MiB rehash
transient = 67 MiB, over the cap. The bulk: kept replays 23.2 MiB (the scene
journal 4.6 MiB each, filled with per-radar track transitions), Ground.known
10.9 MiB (277k columns; the old sweep only ran above 300k and kept everything
younger than 2000 ticks, so a wide query pattern grew it without bound and
the next rehash doubled the table), the live recording 7.5 MiB, radar tracks
3.2 MiB.

Bounds, derived from the 64 MiB budget (Sim::memory reports each consumer):
- Ground.known: KNOWN_MAX 100_000 columns (~2.7 MiB steady, ~8.2 MiB through
  a rehash at 24 B + control byte per entry, 7/8 load). Over the cap the
  oldest answers go down to three quarters (a sweep is not every tick),
  ordered by (age, column) so the sweep is deterministic; heights past
  SWEEP_AGE go with them. Evicted columns are asked again when next needed —
  the cache is reconstructible, no target, frequency or precision is cut.
- Scene journal: MAX_SCENE_EVENTS 65_536 -> 24_576 (~1.7 MiB), and the track
  transitions (acquire/handoff/lock/lost — they grow with systems x contacts,
  the journal's bulk under a large raid) get their own 8_192 budget; beyond
  it the later ones are not recorded. Launches, fires and outcomes keep the
  rest of the journal; chains() already tolerates missing steps.
- Flight track points: MAX_TRACK_POINTS 2 MiB per recording; over it every
  other point is kept and the ticks between points double (Track::step, the
  #142 decimation pattern for the systems' poses). Replay readers use the
  track's own step.

Replica peak after: 24.5 MiB steady + 5.5 MiB transient = 30 MiB, under the
48 MiB headroom target; the fight resolves (376 intercepts, sky clears) and
the same seed replays the same ordered trace. The saturation checkpoint is
untouched (314 / 2022 / 184): its cache stays under the cap.

Co-Authored-By: Kimi Code <noreply@moonshot.ai>
2026-11-21 17:55:54 +03:00
..