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
@@ -0,0 +1,3 @@
## 2024-05-04 - TaskGroup Serialization in Actors
**Learning:** In Swift Concurrency, when an actor creates a `TaskGroup` and its subtasks call an `isolated` method on the same actor, execution is serialized on the actor's executor, destroying parallelism.
**Action:** Mark computationally intensive or state-independent methods called from `TaskGroup` subtasks as `nonisolated` (like `NodeModulesScanner.findNodeModules`) so they run concurrently on the global pool.
6 changes: 4 additions & 2 deletions Sources/Cacheout/Scanner/NodeModulesScanner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ actor NodeModulesScanner {
.sorted { $0.sizeBytes > $1.sizeBytes }
}

private func findNodeModules(in directory: URL, maxDepth: Int, currentDepth: Int = 0) async -> [NodeModulesItem] {
nonisolated private func findNodeModules(in directory: URL, maxDepth: Int, currentDepth: Int = 0) async -> [NodeModulesItem] {
let fileManager = FileManager.default
guard currentDepth < maxDepth else { return [] }

var results: [NodeModulesItem] = []
Expand Down Expand Up @@ -120,7 +121,8 @@ actor NodeModulesScanner {
return results
}

private func directorySize(at url: URL) -> Int64 {
nonisolated private func directorySize(at url: URL) -> Int64 {
let fileManager = FileManager.default
var total: Int64 = 0
guard let enumerator = fileManager.enumerator(
at: url,
Expand Down