Repository: apple/swift-nio
File: Sources/NIOFileSystem/CopyStrategy.swift (Swift)

Code before:
        // error check is desirable over validating on downstream use.
        case parallel(_ maxDescriptors: Int)
    }

    internal let wrapped: Wrapped
    private init(_ wrapped: Wrapped) {
        self.wrapped = wrapped
    }

    // These selections are relatively arbitrary but the rationale is as follows:
    //
    // - Never exceed the default OS limits even if 4 such operations were happening at once.
    // - Sufficient to enable significant speed up from parallelism
    // - Not wasting effort by pushing contention to the underlying storage device. Further we
    //   assume an SSD or similar underlying storage tech. Users on spinning rust need to account
    //   for that themselves anyway.
    //
    // That said, empirical testing for this has not been performed, suggestions welcome.
    //
    // Note: for now we model the directory scan as needing two handles because, during the creation
    // of the destination directory we hold the handle for a while copying attributes
    // a much more complex internal state machine could allow doing two of these if desired
    // This may not result in a faster copy though so things are left simple
    internal static func determinePlatformDefault() -> Wrapped {
        #if os(macOS) || os(Linux) || os(Windows)
        // 4 concurrent file copies/directory scans. Avoiding storage system contention is of upmost
        // importance.
        //
        // Testing was performed on an SSD, while copying objects (a dense directory of small files
        // and subdirectories of similar shape) to the same volume, totalling 12GB. Results showed
        // improvements in elapsed time for (expected) increases in CPU time up to parallel(8).
        // Beyond this, the increases in CPU led to only moderate gains.
        //
        // Anyone tuning this is encouraged to cover worst case scenarios.
        return .parallel(8)
        #elseif os(iOS) || os(tvOS) || os(watchOS) || os(Android)
        // Reduced maximum descriptors in embedded world. This is chosen based on biasing towards
        // safety, not empirical testing.
        return .parallel(4)
        #else
        // Safety first. If we do not know what system we run on, we keep it simple.
        return .sequential
        #endif
    }
}

extension CopyStrategy {
    // A copy fundamentally can't work without two descriptors unless you copy
    // everything into memory which is infeasible/inefficient for large copies.
    private static let minDescriptorsAllowed = 2


Review comment (suggestion):
```suggestion
        // 4 concurrent file copies/directory scans. Avoiding storage system contention is of utmost
```

Code after:
        // error check is desirable over validating on downstream use.
        case parallel(_ maxDescriptors: Int)
    }

    internal let wrapped: Wrapped
    private init(_ wrapped: Wrapped) {
        self.wrapped = wrapped
    }

    // These selections are relatively arbitrary but the rationale is as follows:
    //
    // - Never exceed the default OS limits even if 4 such operations were happening at once.
    // - Sufficient to enable significant speed up from parallelism
    // - Not wasting effort by pushing contention to the underlying storage device. Further we
    //   assume an SSD or similar underlying storage tech. Users on spinning rust need to account
    //   for that themselves anyway.
    //
    // That said, empirical testing for this has not been performed, suggestions welcome.
    //
    // Note: for now we model the directory scan as needing two handles because, during the creation
    // of the destination directory we hold the handle for a while copying attributes
    // a much more complex internal state machine could allow doing two of these if desired
    // This may not result in a faster copy though so things are left simple
    internal static func determinePlatformDefault() -> Wrapped {
        #if os(macOS) || os(Linux) || os(Windows)
        // 4 concurrent file copies/directory scans. Avoiding storage system contention is of utmost
        // importance.
        //
        // Testing was performed on an SSD, while copying objects (a dense directory of small files
        // and subdirectories of similar shape) to the same volume, totalling 12GB. Results showed
        // improvements in elapsed time for (expected) increases in CPU time up to parallel(8).
        // Beyond this, the increases in CPU led to only moderate gains.
        //
        // Anyone tuning this is encouraged to cover worst case scenarios.
        return .parallel(8)
        #elseif os(iOS) || os(tvOS) || os(watchOS) || os(Android)
        // Reduced maximum descriptors in embedded world. This is chosen based on biasing towards
        // safety, not empirical testing.
        return .parallel(4)
        #else
        // Safety first. If we do not know what system we run on, we keep it simple.
        return .sequential
        #endif
    }
}

extension CopyStrategy {
    // A copy fundamentally can't work without two descriptors unless you copy
    // everything into memory which is infeasible/inefficient for large copies.
    private static let minDescriptorsAllowed = 2