Skip to content
Merged
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 @@ -32,3 +32,6 @@
## 2024-05-30 - SwiftUI ForEach and Lazy Collections
**Learning:** In SwiftUI, avoid using `.lazy.filter` directly inside a `ForEach` loop, as `ForEach` requires the data to conform to `RandomAccessCollection`, which `LazyFilterSequence` does not. Eagerly compute the filtered array before passing it to the `ForEach` view builder.
**Action:** When optimizing SwiftUI views, only apply `.lazy.filter` to properties where you immediately consume the sequence (e.g., calling `.count`, `.reduce`, or `.sorted()`). For data bound to a `ForEach` list, continue using standard eager `.filter`.
## 2025-04-13 - Loop Filtering and Intermediate Allocations
**Learning:** In Swift, using `.filter` before a `for` loop eagerly allocates a new intermediate array, causing unnecessary memory churn and processing overhead, especially during frequent operations like system monitoring.
**Action:** Use `for ... where` clauses instead of eagerly filtering the collection prior to the loop (e.g., `for item in array where condition { ... }`). This prevents the allocation of intermediate arrays and improves efficiency.
8 changes: 2 additions & 6 deletions Sources/Cacheout/Memory/RecommendationEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,7 @@ struct RecommendationEngine {
}

// rosetta_detected
let rosettaProcesses = scanResult.processes.filter {
$0.isRosetta && $0.physFootprint >= Self.rosettaMinFootprint
}
for proc in rosettaProcesses {
for proc in scanResult.processes where proc.isRosetta && proc.physFootprint >= Self.rosettaMinFootprint {
let footprintGB = Double(proc.physFootprint) / (1024 * 1024 * 1024)
recommendations.append(Recommendation(
type: .rosettaDetected,
Expand All @@ -223,8 +220,7 @@ struct RecommendationEngine {
}

// agent_memory_pressure
let agents = AgentDetector.agentProcesses(from: scanResult.processes)
for agent in agents where agent.physFootprint >= Self.agentMinFootprint {
for agent in scanResult.processes where AgentDetector.isAgent(agent) && agent.physFootprint >= Self.agentMinFootprint {
let footprintGB = Double(agent.physFootprint) / (1024 * 1024 * 1024)
recommendations.append(Recommendation(
type: .agentMemoryPressure,
Expand Down
Loading