Skip to content

⚡ Bolt: optimize expensive calculations in render#54

Open
Smensink wants to merge 1 commit intomainfrom
bolt-optimize-render-calculations-10904413349669687798
Open

⚡ Bolt: optimize expensive calculations in render#54
Smensink wants to merge 1 commit intomainfrom
bolt-optimize-render-calculations-10904413349669687798

Conversation

@Smensink
Copy link
Copy Markdown
Owner

@Smensink Smensink commented Feb 6, 2026

💡 What: Optimized getSelectedIds utility with WeakMap cache and gated its usage in key components. Memoized filtering/pagination in AuthorDetailsSeason.
🎯 Why: Redundant O(N) calculations were being performed on every render of list-heavy pages.
📊 Impact: Significant reduction in CPU usage during re-renders. Repeated selection list calculations are now O(1).
🔬 Measurement: Verified that selection calculation is skipped when not in editor mode and that getSelectedIds uses cache for stable state references.


PR created automatically by Jules for task 10904413349669687798 started by @Smensink

This PR implements several performance optimizations to reduce redundant O(N) calculations during the React render cycle:

1.  **Global `getSelectedIds` Optimization**: Added a `WeakMap` cache to `getSelectedIds.js`. In an immutable state world, this turns repeated calls with the same state object (e.g., during re-renders) from O(N) to O(1).
2.  **Gated Selection Calculation**: In `AuthorDetails`, `AuthorIndex`, and `BookIndex`, `getSelectedIds()` is now only called when `isEditorActive` is true. This prevents O(N) work on every render when the bulk editor is not in use.
3.  **Memoized Filtering and Pagination**: In `AuthorDetailsSeason`, implemented manual memoization for the filter and pagination logic to skip redundant O(N) filtering when the items or filter string haven't changed.

These changes collectively improve the responsiveness of the application's most data-heavy views.

Co-authored-by: Smensink <41000986+Smensink@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant