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
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,6 @@
## 2025-10-24 - Bulk Disk I/O Parallelization and Thread Pool Deadlocks
**Learning:** Attempting to parallelize synchronous bulk I/O operations (like `FileManager.removeItem` loops) using just `TaskGroup` or `Task.detached` can exhaust the Swift cooperative thread pool and cause deadlocks, because `Task.detached` does NOT escape the thread pool.
**Action:** To optimize bulk I/O operations, parallelize them using `withThrowingTaskGroup` combined with a sliding window iterator (e.g., `maxConcurrency` of 8). Wrap synchronous blocking calls in `withCheckedThrowingContinuation` and explicitly dispatch them to a background GCD queue (e.g., `DispatchQueue.global(qos: .userInitiated).async`) to prevent thread pool starvation.
## 2024-05-24 - Array Allocation and Short-Circuiting in SwiftUI
**Learning:** Checking `.isEmpty` on a computed property that wraps an eager `.filter` causes an unnecessary O(N) allocation. Eager `.filter` followed by `.reduce` also forces intermediate memory allocation, which is particularly expensive for computed properties used in SwiftUI views.
**Action:** Always use `.contains(where:)` to short-circuit existence checks, and chain `.lazy.filter` before `.reduce` to iterate over elements without allocating temporary arrays.
6 changes: 4 additions & 2 deletions Sources/Cacheout/ViewModels/CacheoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ class CacheoutViewModel: ObservableObject {
scanResults.filter { $0.isSelected }
}

// ⚑ Bolt Optimization: Chained .lazy.filter before .reduce to avoid unnecessary O(n) intermediate array allocations. Expected impact: Reduces memory churn during UI updates.
var selectedSize: Int64 {
selectedResults.reduce(0) { $0 + $1.sizeBytes }
scanResults.lazy.filter(\.isSelected).reduce(0) { $0 + $1.sizeBytes }
}

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

var hasResults: Bool { !scanResults.isEmpty || !nodeModulesItems.isEmpty }
var hasSelection: Bool { !selectedResults.isEmpty || selectedNodeModulesSize > 0 }
// ⚑ Bolt Optimization: Use .contains(where:) instead of checking .isEmpty on a filtered array to short-circuit evaluation. Expected impact: O(1) best-case execution instead of O(n) filtering.
var hasSelection: Bool { scanResults.contains(where: \.isSelected) || selectedNodeModulesSize > 0 }

// MARK: - Node Modules computed properties

Expand Down
Loading