From 49035abf63b021a5bf8a316bd99c2a70e040ea97 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 8 Jun 2026 05:19:16 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Optimize=20collection=20count=20computations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added `.lazy` before `.filter { ... }.count` in SwiftUI view computations to avoid eager allocation of intermediate arrays. Co-authored-by: acebytes <2820910+acebytes@users.noreply.github.com> --- .jules/bolt.md | 3 +++ Sources/Cacheout/Views/CleanConfirmation.swift | 2 +- Sources/Cacheout/Views/MenuBarView.swift | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index b2c1128..9ccb6de 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -28,3 +28,6 @@ ## 2025-10-24 - Bulk Disk I/O Parallelization and Thread Pool Starvation **Learning:** Both `withTaskGroup` and `Task.detached` schedule their work on Swift's cooperative thread pool, which has only as many threads as the CPU has cores. Running synchronous blocking I/O (like `FileManager.removeItem`) directly inside such tasks ties up cooperative threads — when every thread is parked in a syscall there is nothing left to advance other Swift Concurrency work, which manifests as starvation and (with self-referential `await` chains) outright deadlock. `Task.detached` does not help here: "detached" means unstructured/independent, not "off the cooperative pool." **Action:** To parallelize bulk blocking I/O, combine a sliding-window `withThrowingTaskGroup` (e.g., `maxConcurrency` of 8) with a per-item handoff to a GCD queue: wrap the blocking call in `withCheckedThrowingContinuation` and dispatch it via `DispatchQueue.global(qos: .userInitiated).async { ... continuation.resume(...) }`. The cooperative-pool task only `await`s the continuation, so it never holds a thread while the syscall runs. +## 2026-11-15 - Lazy Filter Counts Avoid Intermediate Arrays +**Learning:** Using an eager `.filter { ... }.count` operation on collections within SwiftUI view bodies allocates a full intermediate array on every render pass just to evaluate the length. +**Action:** Chain `.lazy.filter { ... }.count` to prevent the intermediate array allocation while retaining O(N) evaluation time. diff --git a/Sources/Cacheout/Views/CleanConfirmation.swift b/Sources/Cacheout/Views/CleanConfirmation.swift index 58f679b..da9fba6 100644 --- a/Sources/Cacheout/Views/CleanConfirmation.swift +++ b/Sources/Cacheout/Views/CleanConfirmation.swift @@ -36,7 +36,7 @@ struct CleanConfirmationSheet: View { Text("Clean Selected Caches?") .font(.title2.bold()) - Text("This will remove \(viewModel.formattedTotalSelectedSize) from \(viewModel.selectedResults.count + viewModel.nodeModulesItems.filter(\.isSelected).count) items.") + Text("This will remove \(viewModel.formattedTotalSelectedSize) from \(viewModel.selectedResults.count + viewModel.nodeModulesItems.lazy.filter(\.isSelected).count) items.") .font(.body) .foregroundStyle(.secondary) .multilineTextAlignment(.center) diff --git a/Sources/Cacheout/Views/MenuBarView.swift b/Sources/Cacheout/Views/MenuBarView.swift index 9084b59..67efaba 100644 --- a/Sources/Cacheout/Views/MenuBarView.swift +++ b/Sources/Cacheout/Views/MenuBarView.swift @@ -154,7 +154,7 @@ struct MenuBarView: View { Spacer() statPill( label: "Categories", - value: "\(viewModel.scanResults.filter { !$0.isEmpty }.count)", + value: "\(viewModel.scanResults.lazy.filter { !$0.isEmpty }.count)", color: .blue ) }