Skip to content
Closed
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: 3 additions & 1 deletion Sources/Cacheout/ViewModels/CacheoutViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ class CacheoutViewModel: ObservableObject {
}

var selectedSize: Int64 {
selectedResults.reduce(0) { $0 + $1.sizeBytes }
// ⚑ Bolt: Optimized by using .lazy.filter before .reduce to prevent intermediate array allocation
// Expected Impact: Reduces memory churn and array allocation overhead on UI updates
scanResults.lazy.filter(\.isSelected).reduce(0) { $0 + $1.sizeBytes }
}

var formattedSelectedSize: String {
Expand Down
7 changes: 6 additions & 1 deletion Sources/Cacheout/Views/MenuBarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ struct MenuBarView: View {
Spacer()
statPill(
label: "Categories",
value: "\(viewModel.scanResults.filter { !$0.isEmpty }.count)",
// ⚑ Bolt: Optimized by using .lazy.filter.count to prevent intermediate array allocation
// Expected Impact: Eliminates eager O(N) array allocation when computing the category count
value: "\(viewModel.scanResults.lazy.filter { !$0.isEmpty }.count)",
color: .blue
)
}
Expand All @@ -177,7 +179,10 @@ struct MenuBarView: View {
// MARK: - Top Categories

private var topCategories: some View {
// ⚑ Bolt: Optimized by using .lazy.filter before .sorted to prevent intermediate array allocation
// Expected Impact: Reduces memory footprint by avoiding an intermediate filtered array before sorting
let top = viewModel.scanResults
.lazy
.filter { !$0.isEmpty }
.sorted { $0.sizeBytes > $1.sizeBytes }
.prefix(5)
Expand Down
Loading