Skip to content

⚡ Bolt: optimize Sprite component rendering and asset loading#75

Merged
b0x1 merged 1 commit intomainfrom
bolt-sprite-optimization-2004112129294971924
Apr 22, 2026
Merged

⚡ Bolt: optimize Sprite component rendering and asset loading#75
b0x1 merged 1 commit intomainfrom
bolt-sprite-optimization-2004112129294971924

Conversation

@b0x1
Copy link
Copy Markdown
Owner

@b0x1 b0x1 commented Apr 21, 2026

This PR implements a set of systemic performance optimizations for the Sprite component, which is used extensively for rendering tiles, units, and resources.

💡 What:

  1. Memoization: Wrapped the Sprite component in React.memo to skip re-renders when props haven't changed.
  2. Computation Caching: Moved calculateSheetSize outside the render loop and used a WeakMap to cache results. Previously, this $O(N)$ calculation (where $N$ is the number of frames in the manifest) happened on every single render.
  3. Fetch Coalescing: Added a pendingManifests cache to ensure that if multiple sprites request the same manifest (e.g., during map loading), only one fetch call is made.
  4. Cleanup: Standardized constants and fixed linting issues.

🎯 Why:
The Sprite component is a high-frequency leaf component. In screens like the Settlement Screen or during map panning, hundreds of Sprite instances can be active. Reducing the per-instance overhead significantly improves UI responsiveness and reduces CPU/Network spikes.

📊 Impact:

  • Eliminates redundant $O(N)$ manifest parsing on every render.
  • Reduces network overhead by deduplicating manifest fetches.
  • Prevents unnecessary React reconciliation for static sprites.

🔬 Measurement:

  • Verified that game rendering remains correct via Playwright screenshots.
  • Confirmed pnpm run check (Lint/Type/Test) passes.
  • Logical complexity of derived state calculation reduced from $O(N)$ to $O(1)$ cached.

PR created automatically by Jules for task 2004112129294971924 started by @b0x1

- Wrap Sprite component in React.memo to prevent redundant re-renders.
- Implement WeakMap caching for manifest sheet size calculations to turn O(N) work into O(1) lookups.
- Coalesce concurrent network requests for the same manifest file using a pending promise cache.
- Replace hardcoded tile size constants with MAP_CONSTANTS.TILE_SIZE for consistency.
- Address ESLint warnings for floating promises and dynamic deletes.

Co-authored-by: b0x1 <21123655+b0x1@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 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 deeb363 into main Apr 22, 2026
5 checks passed
@b0x1 b0x1 deleted the bolt-sprite-optimization-2004112129294971924 branch April 22, 2026 19:20
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