diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..7cb4036 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-24 - Actor Serialization in TaskGroup +**Learning:** In Swift structured concurrency, using an `actor` to manage a `withTaskGroup` where tasks invoke synchronous, blocking I/O (like `FileManager` operations) directly on the actor inadvertently serializes the tasks, preventing parallelism. +**Action:** For stateless components interacting with thread-safe dependencies (like `FileManager.default`), use `struct`s or `nonisolated` methods to allow tasks to execute concurrently across threads. diff --git a/Sources/Cacheout/Scanner/CacheScanner.swift b/Sources/Cacheout/Scanner/CacheScanner.swift index 3ce3e9c..1ded582 100644 --- a/Sources/Cacheout/Scanner/CacheScanner.swift +++ b/Sources/Cacheout/Scanner/CacheScanner.swift @@ -26,7 +26,9 @@ import Foundation -actor CacheScanner { +// Using struct instead of actor to prevent serialization of parallel tasks. +// Since this component is stateless, struct allows true concurrency across threads. +struct CacheScanner { private let fileManager = FileManager.default func scanAll(_ categories: [CacheCategory]) async -> [ScanResult] { diff --git a/Sources/Cacheout/Scanner/NodeModulesScanner.swift b/Sources/Cacheout/Scanner/NodeModulesScanner.swift index 3ed4d8c..2a9a5a6 100644 --- a/Sources/Cacheout/Scanner/NodeModulesScanner.swift +++ b/Sources/Cacheout/Scanner/NodeModulesScanner.swift @@ -28,7 +28,9 @@ import Foundation -actor NodeModulesScanner { +// Using struct instead of actor to prevent serialization of parallel tasks. +// Since this component is stateless, struct allows true concurrency across threads. +struct NodeModulesScanner { private let fileManager = FileManager.default /// Common directories where developers keep projects