Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@
## 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.

## 2024-05-24 - Short-circuiting Computed Properties
**Learning:** In SwiftUI view models, checking if a filtered array is empty (`!array.filter { ... }.isEmpty`) or computing a full reduction (`array.lazy.filter { ... }.reduce(0, +) > 0`) to determine a simple boolean state causes unnecessary O(N) traversal and intermediate array allocation on every UI render cycle.
**Action:** Use `.contains(where: { ... })` to short-circuit evaluation. It stops iterating as soon as a match is found (best case O(1)) and avoids allocating intermediate collections.
7 changes: 5 additions & 2 deletions Sources/Cacheout/ViewModels/CacheoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class CacheoutViewModel: ObservableObject {
}

var selectedSize: Int64 {
selectedResults.reduce(0) { $0 + $1.sizeBytes }
// ⚑ Bolt: Use .lazy.filter before .reduce to prevent intermediate array allocation
scanResults.lazy.filter(\.isSelected).reduce(0) { $0 + $1.sizeBytes }
}

var formattedSelectedSize: String {
Expand All @@ -118,7 +119,9 @@ class CacheoutViewModel: ObservableObject {
}

var hasResults: Bool { !scanResults.isEmpty || !nodeModulesItems.isEmpty }
var hasSelection: Bool { !selectedResults.isEmpty || selectedNodeModulesSize > 0 }

// ⚑ Bolt: Use .contains(where:) to short-circuit evaluation instead of checking .isEmpty on a filtered array
var hasSelection: Bool { scanResults.contains(where: \.isSelected) || nodeModulesItems.contains(where: \.isSelected) }

// MARK: - Node Modules computed properties

Expand Down
Loading