Finding
Several src/sim hot paths allocate Maps/Sets/arrays/objects/strings on every tick. The most visible offender is combat:
src/sim/combat.ts:40-68 allocates a Map, tile arrays, sorted Array.from(bucket.keys()), and a Set during the per-tick combat sweep.
src/sim/combat.ts:170-190 allocates another Map, per-colony arrays, and a sorted key array inside tile resolution.
Additional recurring tick allocations:
src/sim/tick.ts:1046-1053 allocates and sorts eligible every colony task-assignment pass.
src/sim/tick.ts:1058-1063 allocates a need object every colony pass.
src/sim/tick.ts:1194-1200 calls gridKey.split(':') during pheromone decay.
Impact
This violates the no-per-tick-allocation discipline in the project instructions and makes sim scaling harder to reason about. Combat is especially costly because the sweep runs on every sim tick, including steady-state/no-combat ticks.
Suggested direction
Replace these with reusable scratch structures or typed-array buckets owned by the sim loop. For pheromones, avoid parsing metadata from string keys on every tick; keep the pheromone type available structurally or cache parsed metadata with the grid.
Add an allocation-oriented regression/profiling check for a stable world over many ticks so this does not creep back in as Phase 3 complexity grows.
Review provenance
Confirmed by an independent fresh-context review agent during the 2026-05-28 adversarial codebase review of origin/main (16e4201).
Finding
Several
src/simhot paths allocate Maps/Sets/arrays/objects/strings on every tick. The most visible offender is combat:src/sim/combat.ts:40-68allocates aMap, tile arrays, sortedArray.from(bucket.keys()), and aSetduring the per-tick combat sweep.src/sim/combat.ts:170-190allocates anotherMap, per-colony arrays, and a sorted key array inside tile resolution.Additional recurring tick allocations:
src/sim/tick.ts:1046-1053allocates and sortseligibleevery colony task-assignment pass.src/sim/tick.ts:1058-1063allocates aneedobject every colony pass.src/sim/tick.ts:1194-1200callsgridKey.split(':')during pheromone decay.Impact
This violates the no-per-tick-allocation discipline in the project instructions and makes sim scaling harder to reason about. Combat is especially costly because the sweep runs on every sim tick, including steady-state/no-combat ticks.
Suggested direction
Replace these with reusable scratch structures or typed-array buckets owned by the sim loop. For pheromones, avoid parsing metadata from string keys on every tick; keep the pheromone type available structurally or cache parsed metadata with the grid.
Add an allocation-oriented regression/profiling check for a stable world over many ticks so this does not creep back in as Phase 3 complexity grows.
Review provenance
Confirmed by an independent fresh-context review agent during the 2026-05-28 adversarial codebase review of
origin/main(16e4201).