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
12 changes: 6 additions & 6 deletions Sources/Cacheout/Memory/RecommendationEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,9 @@ struct RecommendationEngine {
}

// rosetta_detected
let rosettaProcesses = scanResult.processes.filter {
$0.isRosetta && $0.physFootprint >= Self.rosettaMinFootprint
}
for proc in rosettaProcesses {
// ⚡ Bolt Optimization: Using a `where` clause on the `for` loop instead of an eager `.filter`
// prevents the allocation of an intermediate array, saving memory churn when scanning hundreds of processes.
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 +222,9 @@ struct RecommendationEngine {
}

// agent_memory_pressure
let agents = AgentDetector.agentProcesses(from: scanResult.processes)
for agent in agents where agent.physFootprint >= Self.agentMinFootprint {
// ⚡ Bolt Optimization: Checking `isAgent` in the `where` clause rather than running an eager `.filter`
// prevents an intermediate array allocation.
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
3 changes: 2 additions & 1 deletion Sources/Cacheout/Views/CleanConfirmation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ 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.")
// ⚡ Bolt Optimization: Using `.lazy.filter` prevents an intermediate array allocation here.
Text("This will remove \(viewModel.formattedTotalSelectedSize) from \(viewModel.selectedResults.count + viewModel.nodeModulesItems.lazy.filter(\.isSelected).count) items.")
.font(.body)
.foregroundStyle(.secondary)
.multilineTextAlignment(.center)
Expand Down
6 changes: 5 additions & 1 deletion Sources/Cacheout/Views/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ struct MenuBarView: View {
Spacer()
statPill(
label: "Categories",
value: "\(viewModel.scanResults.filter { !$0.isEmpty }.count)",
// ⚡ Bolt Optimization: Using `.lazy.filter` before `.count` prevents Swift from allocating an intermediate array.
value: "\(viewModel.scanResults.lazy.filter { !$0.isEmpty }.count)",
color: .blue
)
}
Expand All @@ -177,7 +178,10 @@ struct MenuBarView: View {
// MARK: - Top Categories

private var topCategories: some View {
// ⚡ Bolt Optimization: Chaining `.lazy.filter` before `.sorted` avoids allocating an intermediate array
// during SwiftUI render passes, reducing unnecessary heap allocations.
let top = viewModel.scanResults
.lazy
.filter { !$0.isEmpty }
.sorted { $0.sizeBytes > $1.sizeBytes }
.prefix(5)
Expand Down
Loading