mirror of
https://github.com/koala73/worldmonitor.git
synced 2026-04-25 17:14:57 +02:00
3.0 KiB
3.0 KiB
status, priority, issue_id, tags, dependencies
| status | priority | issue_id | tags | dependencies | |||||
|---|---|---|---|---|---|---|---|---|---|
| pending | p3 | 192 |
|
Performance micro-cleanups (buildPreMeta x8, signal indexing, evidence chokepoint filter, prototype-pollution guards)
Problem Statement
Several minor perf and safety cleanups:
buildPreMeta(sources)is called 8x with identical results (only depends on sources, not regionId). Hoist out ofcomputeSnapshotintomain().signals.filter(theater substring)rebuilds per region inbalance-vector.mjsandevidence-collector.mjs. PrecomputesignalsByRegionMap once inmain().evidence-collector.mjs:62-77iterates ALL chokepoints regardless of region. Filter bygetRegionCorridors(regionId).map(c => c.chokepointId).geography.js:countryCriticality()andregionForCountry()use bracket access on plain objects - prototype pollution risk ifiso2is__proto__. UseObject.hasOwn()guard.JSON.stringify(snapshot)happens twice inpersist-snapshot.mjs(for tsKey and idKey). Stringify once, reuse.actor-scoring.mjs,balance-vector.mjs,scenario-builder.mjsJSON.stringifyoncaseFilenot wrapped in try/catch. Circular references in upstream payload would crash the seed for all 8 regions.
Findings
- #1-3, #5 are pure perf: redundant work per region
- #4 is a safety issue (bracket access on user-supplied string keys)
- #6 is a reliability issue (one bad forecast crashes the whole seed)
- All items small, independent, safe
Proposed Solutions
Option 1: Do all 6 in one PR
Small mechanical cleanups; low risk.
Pros: Single follow-up Cons: Mix of concerns Effort: Small (each item) Risk: Low
Option 2: Split perf vs safety
(a) perf micros (#1, #2, #3, #5), (b) safety (#4, #6).
Pros: Each PR has a clean theme Cons: More overhead Effort: Small Risk: Low
Recommended Action
Technical Details
Affected files:
scripts/seed-regional-snapshots.mjs- main(), computeSnapshot, buildPreMeta call sitescripts/regional-snapshot/balance-vector.mjs- signals.filter, caseFile stringifyscripts/regional-snapshot/evidence-collector.mjs:62-77- chokepoint iterationscripts/regional-snapshot/actor-scoring.mjs- caseFile stringifyscripts/regional-snapshot/scenario-builder.mjs- caseFile stringifyscripts/regional-snapshot/persist-snapshot.mjs- double stringifyshared/geography.js- countryCriticality, regionForCountry
For #4, pattern:
if (!Object.hasOwn(table, iso2)) return fallback;
return table[iso2];
For #6, wrap each JSON.stringify(f?.caseFile ?? ...) in try/catch and fall back to "{}" (ties in naturally with issue #190's precompute-once).
Acceptance Criteria
- buildPreMeta hoisted to main()
- signalsByRegion indexed once
- Chokepoint evidence filtered by region corridors
- Object.hasOwn guards on geography lookups
- JSON.stringify(snapshot) called once per region
- caseFile JSON.stringify wrapped in try/catch with fallback to {}
Work Log
Resources
- PR #2940
- PR #2942