Skip to content

⚡ Bolt: Optimize production loop and population calculation#97

Merged
b0x1 merged 1 commit into
mainfrom
bolt-production-optimizations-8799583549388148644
May 20, 2026
Merged

⚡ Bolt: Optimize production loop and population calculation#97
b0x1 merged 1 commit into
mainfrom
bolt-production-optimizations-8799583549388148644

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

This PR implements two targeted performance improvements in the game's core logic:

  1. Production Loop Optimization: In TurnEngine.ts, determining if a queued item was a building or a unit previously involved calling Object.values() on every iteration of the settlement production loop. This has been replaced with module-level Set constants, providing $O(1)$ lookup time and reducing garbage collection pressure.
  2. Population Calculation Optimization: The calculatePopulation function in Settlement.ts was using a .filter().length pattern, which creates a new array every time it is called. This has been refactored into a simple for...of loop 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

- 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.
@google-labs-jules

Copy link
Copy Markdown
Contributor Author

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@b0x1 b0x1 merged commit 1b9094a into main May 20, 2026
5 checks passed
@b0x1 b0x1 deleted the bolt-production-optimizations-8799583549388148644 branch May 20, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant