⚡ Bolt: Optimize @Published array mutations to reduce UI re-renders#125
⚡ Bolt: Optimize @Published array mutations to reduce UI re-renders#125
Conversation
Replaced `for` loops that updated individual elements of the `@Published` arrays `scanResults` and `nodeModulesItems` with `.map` closures. This batches the updates into a single assignment, preventing SwiftUI/Combine from firing `objectWillChange` notifications for every single element modified in the loop. Co-authored-by: acebytes <2820910+acebytes@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:
Refactored the array selection/deselection methods in
CacheoutViewModel(selectAllSafe,deselectAll,selectStaleNodeModules,selectAllNodeModules,deselectAllNodeModules) to use functional.mapoperations instead of mutating elements in place withinforloops.🎯 Why:
In SwiftUI
ObservableObjectview models, mutating individual properties of a struct within a@Publishedarray inside a loop triggers a UI update notification (objectWillChange) for every single change. This causes excessive re-renders when selecting or deselecting many items at once.📊 Impact:
Reduces Combine property observer notifications from O(N) to O(1) during mass selection operations, significantly reducing unnecessary SwiftUI view recalculations and making the UI feel more responsive during "Smart Clean" or "Select All" actions.
🔬 Measurement:
To verify, you can add a
printstatement inside the view'sbodythat lists the results, run the app, and click "Select All Safe". Before this change, the view body would evaluate multiple times (once for each safe item selected). After this change, the view body evaluates exactly once for the single array re-assignment.PR created automatically by Jules for task 7835873494791974428 started by @acebytes