macOS 15 + Xcode 16 Beta 4 Problem with .task {} and async function

Hi everyone,

when I was doing some testing on macOS 15 + Xcode 16 Beta 4 I noticed that my app's performance took a significant hit. A simple task that previously was completed within 15 seconds or less now took about a minute to complete.

I came to the conclusion that the only plausible cause could be the way .task {} and asynchronous functions are handled.

Starting several .task{} and calling async functions from within using macOS 14.5 and Xcode 15.4 results in following log output:

task1 started
task3 started
task2 started
task4 started
         --> task2 ended
         --> task3 ended
         --> task4 ended
         --> task1 ended`

Running the same code on macOS 15.0 + Xcode 16 Beta 4 will result in the following log output:

task1 started
         --> task1 ended
task2 started
         --> task2 ended
task3 started
         --> task3 ended
task4 started
         --> task4 ended

In the first example the code is executed in 'parallel'. All tasks are started and doing there respective work. In second example a task is started and we are waiting for it to complete before the other tasks are started.

I could start to rewrite my code to get the results I desire, however I'm wondering if this is a bug in regards to macOS 15 + Xcode 16 Beta 4 and the way .task {} and asynchronous functions are handled. The output is quite different after all.

What's your take on this? If you want to try it out for yourself you can use the following sample code:

import SwiftUI

struct ContentView: View {
    
    func func1() async -> Int {
        print("task1 started")
        var myInt: Int = 0
        while myInt < 999999999 {
            myInt += 1
        }
        print("         --> task1 ended")
        return 1
    }
    
    func func2() async -> Int {
        print("task2 started")
        var myInt: Int = 0
        while myInt < 999999 {
            myInt += 1
        }
        print("         --> task2 ended")
        return 2
    }
    
    func func3() async -> Int {
        print("task3 started")
        var myInt: Int = 0
        while myInt < 999999 {
            myInt += 1
        }
        print("         --> task3 ended")
        return 3
    }
    
    func func4() async -> Int {
        print("task4 started")
        var myInt: Int = 0
        while myInt < 999999999 {
            myInt += 1
        }
        print("         --> task4 ended")
        return 4
    }
    
    var body: some View {
        VStack {
            Text("Hello, world!")
        }
        .task {
            await func1()
        }
        .task {
            await func2()
        }
        .task {
            await func3()
        }
        .task {
            await func4()
        }
    }
}

#Preview {
    ContentView()
}
macOS 15 + Xcode 16 Beta 4 Problem with .task {} and async function
 
 
Q