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-03-30 - Replace actors with structs for parallel TaskGroups
**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`), use `struct`s or `nonisolated` methods to allow tasks in a `TaskGroup` to execute concurrently across threads.
8 changes: 4 additions & 4 deletions Sources/Cacheout/Scanner/CacheScanner.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/// # CacheScanner β€” Parallel Cache Category Scanner
///
/// An `actor` that scans all registered cache categories concurrently using
/// A `struct` that scans all registered cache categories concurrently using
/// Swift's structured concurrency (`TaskGroup`). Each category is scanned in
/// its own child task for maximum parallelism.
///
/// ## Thread Safety
///
/// Uses the `actor` isolation model to ensure thread-safe access to internal state.
/// All public methods are `async` and can be called from any concurrency context.
/// Uses `struct` instead of `actor` to prevent inadvertently serializing
/// synchronous `FileManager` operations inside the `TaskGroup`.
///
/// ## Disk Size Calculation
///
Expand All @@ -26,7 +26,7 @@

import Foundation

actor CacheScanner {
struct CacheScanner {
private let fileManager = FileManager.default

func scanAll(_ categories: [CacheCategory]) async -> [ScanResult] {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Cacheout/Scanner/NodeModulesScanner.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// # NodeModulesScanner β€” Recursive node_modules Finder
///
/// An `actor` that recursively searches common developer project directories
/// A `struct` that recursively searches common developer project directories
/// for `node_modules` folders. Designed to find abandoned or stale dependencies
/// that consume significant disk space.
///
Expand Down Expand Up @@ -28,7 +28,7 @@

import Foundation

actor NodeModulesScanner {
struct NodeModulesScanner {
private let fileManager = FileManager.default

/// Common directories where developers keep projects
Expand Down