⚡ Bolt: Optimize production loop and population calculation#97
Conversation
- Update `TurnEngine.ts` to use pre-calculated `BUILDING_TYPES_SET` and `UNIT_TYPES_SET` for O(1) lookups during construction processing, avoiding redundant `Object.values()` calls and array allocations. - Refactor `calculatePopulation` in `Settlement.ts` to use a manual loop with a counter instead of `.filter().length`, eliminating intermediate array allocations in a frequently called logic path.
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
This PR implements two targeted performance improvements in the game's core logic:
TurnEngine.ts, determining if a queued item was a building or a unit previously involved callingObject.values()on every iteration of the settlement production loop. This has been replaced with module-levelSetconstants, providingcalculatePopulationfunction inSettlement.tswas using a.filter().lengthpattern, which creates a new array every time it is called. This has been refactored into a simplefor...ofloop with a counter, avoiding unnecessary memory allocation.These changes combined reduce CPU cycles and memory churn during the end-turn phase and when updating settlement UI.
PR created automatically by Jules for task 8799583549388148644 started by @b0x1