maniator / maniator/verticopolis
[Feature]: [P2] Engine hot-path scan removal: pickX per-spawn full scan and evaluateStar gate re-scans
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Description
From the full repository audit (2026-07-21, findings AUD-015 and AUD-016, recommendation N-5; report at
_bmad-output/planning-artifacts/reviews/full-repository-audit-2026-07-21/). Companion to #338 (the render-frame congestion memoization), which lands first. Backlog rowengine-hotpath-scans.
Problems
1. pickX scans the entire unit list per spawned person (AUD-015). src/engine/crowd/trips.ts:57-66 builds a tile list from a full tower.units walk per call; it runs twice per spawned trip (origin + destination), up to 8 spawns per outer step, plus once per dwell expiry: up to ~16 full O(25k) scans per sim step, a leading slice of the measured 8.6 ms tick.
2. evaluateStar performs up to ~20 full unit scans per hour (AUD-016). src/engine/sim/star.ts:13-47 re-derives population and each star gate (hasOperational/countOperational/recyclingDemandMet) with fresh full scans across up to 3 ladder iterations, every hour, even when the star cannot move: a named contributor to the 53 ms hour-boundary spike.
Fix directions
- A revision-memoized floor -> structural-tile index for
pickX(the tower already maintainsstructure/lobbyTilesincrementally in register/unregister). Constraint: preservetiles[Math.abs(seed) % tiles.length]ordering so spawn positions stay byte-identical; index insertion order must match unit-array order. - One shared per-kind operational-count pass (plus a single population read) for the gate ladder, or early-exit when the target equals the current star.
Exclusions
The broader per-tick baseline scans (AUD-017: accumulateWaiting + duplicate totalPopulation + spawnFloors sweeps) and the hour-boundary demand-map sharing ride the spec-onhour-boundary-cost activation, sized by the field data from #538; they are not this issue.
Acceptance criteria / required tests
- Golden-master determinism unchanged (spawn positions byte-identical; a test pins
pickXresults against the un-indexed implementation on a populated fixture). - Star evaluation results unchanged across a milestone playthrough (existing milestones integration stays green).
- Measured tick cost on the sixseven_15 save recorded before/after in the PR.
Engine hot path: /gds-code-review.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/engine/crowd/trips.ts:57-66 and src/engine/sim/star.ts:13-47, then inspect the tower's incremental structure/lobbyTiles maintenance. Run the pickX determinism test against a populated fixture and the existing milestones integration; done means byte-identical spawn positions, unchanged star results, and sixseven_15 tick measurements recorded before and after.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- game-dev, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100