This simple executable takes about 8.6s (in debug and release mode) to create and execute 50,000 tasks in a group. Little actual CPU usage during that time, so it seems just enqueuing the work takes a while.
import CoreFoundation
@main
struct ConcurrencyTest {
static func main() async {
let start = CFAbsoluteTimeGetCurrent()
await withTaskGroup(of: Void.self) { group in
@Sendable
func doNothing() {}
for _ in 0..<50_000 {
group.addTask {
doNothing()
}
}
await group.waitForAll()
}
print(CFAbsoluteTimeGetCurrent() - start)
}
}
While running it only used five threads, so there must be other considerations for execution width than just number of cores (this is an i9 iMac with 10/20 cores).