From 9351289b2a13f842860e577b6554a22740c07c47 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 03:57:18 +0000 Subject: [PATCH] Optimize `selectedSize` computation in CacheoutViewModel Update the `selectedSize` computed property in `CacheoutViewModel` to use `scanResults.lazy.filter(\.isSelected).reduce(0) { ... }` instead of using `selectedResults.reduce`. This prevents the creation of a redundant intermediate array of `ScanResult` items every time the property is accessed, which happens frequently during UI renders. This reduces memory churn and improves overall UI performance by switching from an O(n) array allocation to a lazy O(1) space accumulation. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com> --- Sources/Cacheout/ViewModels/CacheoutViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Cacheout/ViewModels/CacheoutViewModel.swift b/Sources/Cacheout/ViewModels/CacheoutViewModel.swift index 27de41a..885c728 100644 --- a/Sources/Cacheout/ViewModels/CacheoutViewModel.swift +++ b/Sources/Cacheout/ViewModels/CacheoutViewModel.swift @@ -106,7 +106,7 @@ class CacheoutViewModel: ObservableObject { } var selectedSize: Int64 { - selectedResults.reduce(0) { $0 + $1.sizeBytes } + scanResults.lazy.filter(\.isSelected).reduce(0) { $0 + $1.sizeBytes } } var formattedSelectedSize: String {