⚡ Bolt: [Performance Improvement] Prevent O(N) allocations and re-renders on missing state item deletions#378
Conversation
… state deletions Avoids O(N) array allocation overhead and prevents unnecessary React rerenders when an element isn't found in state. Co-authored-by: ClarusIubar <101549899+ClarusIubar@users.noreply.github.com>
|
👋 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. |
💡 What: Replaced unconditional
.filter()operations with.findIndex()lookups when removing single items from React state arrays insrc/store/notification-store/actions.tsandsrc/store/notification-store/helpers.ts. When an item is not found, the original array reference is returned to abort the update entirely.🎯 Why: Calling
.filter()always creates a brand new array, triggering O(N) memory allocations, garbage collection pressure, and, importantly, unnecessary React state reconciliations, even if the target item does not exist in the array. This happens frequently when deleting a resource that might be present in some state arrays but not others.📊 Impact: Reduces O(N) memory allocations and eliminates unnecessary React component tree re-renders for missing targets, resulting in a tighter, more efficient state update cycle for deletions.
🔬 Measurement: Review
src/store/notification-store/actions.tsandhelpers.ts. Array object identities remain stable acrossdeleteNotificationdispatches if the item was already absent from the local view. The tests pass cleanly.PR created automatically by Jules for task 12753926019551412995 started by @ClarusIubar