Skip to content

⚡ Bolt: Optimize @Published array mutations to reduce UI re-renders#125

Open
acebytes wants to merge 1 commit intomainfrom
bolt-optimize-array-mutations-7835873494791974428
Open

⚡ Bolt: Optimize @Published array mutations to reduce UI re-renders#125
acebytes wants to merge 1 commit intomainfrom
bolt-optimize-array-mutations-7835873494791974428

Conversation

@acebytes
Copy link
Copy Markdown
Contributor

💡 What:
Refactored the array selection/deselection methods in CacheoutViewModel (selectAllSafe, deselectAll, selectStaleNodeModules, selectAllNodeModules, deselectAllNodeModules) to use functional .map operations instead of mutating elements in place within for loops.

🎯 Why:
In SwiftUI ObservableObject view models, mutating individual properties of a struct within a @Published array 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 print statement inside the view's body that 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

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>
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant