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: 4 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@
## 2026-03-19 - FileManager Enumerator Pre-fetching
**Learning:** Any property requested via `resourceValues(forKeys:)` inside a `FileManager.enumerator` loop must also be in `includingPropertiesForKeys` β€” otherwise `URL.resourceValues` falls back to a synchronous `stat()` per file, turning bulk reads into O(N) disk I/O.
**Action:** Keep the keys array passed to `resourceValues(forKeys:)` a subset of the prefetch list passed to `FileManager.enumerator(at:includingPropertiesForKeys:)`.

## 2024-05-15 - Dictionary initialization performance with reduce(into:)
**Learning:** Standard `for` loop dictionary insertions in Swift can trigger repeated mutation and Copy-On-Write (COW) overhead. Standard `.map` implementations create intermediate array allocations.
**Action:** For efficient and safe initialization of dictionaries/index maps, use `reduce(into: [:])`. This avoids intermediate array allocations and prevents COW overhead by passing the accumulator as an `inout` reference.
7 changes: 3 additions & 4 deletions Sources/Cacheout/Intervention/Tier2Interventions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ public final class JetsamHWM: Intervention {
}

// Step 3: Build priority lookup by PID (keep first entry per PID to avoid trap on duplicates).
var priorityByPID: [pid_t: JetsamPriorityEntryDTO] = [:]
for entry in priorities {
if priorityByPID[entry.pid] == nil {
priorityByPID[entry.pid] = entry
let priorityByPID = priorities.reduce(into: [pid_t: JetsamPriorityEntryDTO]()) { result, entry in
if result[entry.pid] == nil {
result[entry.pid] = entry
}
}

Expand Down