From 7c20732af2375bd597dc654a65b6cdbfecb7ae6f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 17 Jun 2026 05:19:57 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20SwiftUI=20proper?= =?UTF-8?q?ty=20evaluation=20in=20CacheoutViewModel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced eager array allocations and full collection reductions in `selectedSize` and `hasSelection` with `.lazy.filter` and `.contains(where:)`. This avoids intermediate array allocations and provides O(1) best-case evaluation for SwiftUI view updates. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com> --- Sources/Cacheout/ViewModels/CacheoutViewModel.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Sources/Cacheout/ViewModels/CacheoutViewModel.swift b/Sources/Cacheout/ViewModels/CacheoutViewModel.swift index 27de41a..ef60c67 100644 --- a/Sources/Cacheout/ViewModels/CacheoutViewModel.swift +++ b/Sources/Cacheout/ViewModels/CacheoutViewModel.swift @@ -106,7 +106,8 @@ class CacheoutViewModel: ObservableObject { } var selectedSize: Int64 { - selectedResults.reduce(0) { $0 + $1.sizeBytes } + // ⚡ Bolt: Chain .lazy before .filter to prevent intermediate array allocation + scanResults.lazy.filter(\.isSelected).reduce(0) { $0 + $1.sizeBytes } } var formattedSelectedSize: String { @@ -118,7 +119,10 @@ class CacheoutViewModel: ObservableObject { } var hasResults: Bool { !scanResults.isEmpty || !nodeModulesItems.isEmpty } - var hasSelection: Bool { !selectedResults.isEmpty || selectedNodeModulesSize > 0 } + var hasSelection: Bool { + // ⚡ Bolt: Use .contains(where:) for O(1) best-case short-circuiting instead of .isEmpty on filtered array or reducing total size + scanResults.contains(where: \.isSelected) || nodeModulesItems.contains(where: \.isSelected) + } // MARK: - Node Modules computed properties