A House Divided A House DividedDocumentation
Changelog
Engineering/Architecture

Performance hot paths and efficiency notes

Last updated 2026-08-21
Source files

This document captures known high-impact execution paths, recent optimizations, and where deeper profiling belongs for A House Divided. It complements Repo Operating Map and AGENTS.md in AHDGame.

Turn processing ()#

Election resolution ()#

Vote accumulation ()#

NPP context ()#

UI and API#

Area Suggestion
Turn total duration Log or trace phase timings in processTurn (already has durationMs on TurnLog), compare before/after in staging with production-like data volume
MongoDB Atlas or explain() on stateMetrics / states with and without countryIds filter during peak election seasons
React Next.js devtools / React Profiler on dashboard and news feeds with many posts

Hot paths to leave unchanged until tests improve#

Implemented optimizations (audit follow-up)#

Change Rationale
Optional Db for getGameState Removes redundant getDb() in processTurn, initializeGameState, startTurnSystem
Drop unused politicalParties read in resolveGeneralElections Full collection scan with no consumers
getAllStateApprovalsForElection({ countryIds }) from vote accumulation Smaller stateMetrics / states reads when not all countries have active state races

Connected pages