Finishing a HKLiveWorkoutBuilder workout with lots of HKWorkoutActivity instances is very slow

I'm using the new watchOS 9 HKWorkoutActivity in my interval training app (Intervals Pro) for each interval. It's a great addition since all the intervals now show in the Apple Fitness app, however, if the workout has lots of activities then saving the workout is painfully slow. For example, on my Apple Watch Ultra I saved a workout with 63 activities and it took more than 1 minute. Here's a code snippet:

            try await builder.endCollection(at: workoutEndDate)
            try await builder.addMetadata(metadata)
            try await builder.finishWorkout() // This is SLOW

Is anyone else having the same issue?

To demonstrate the issue you can look at a Test Flight build of Intervals Pro: https://testflight.apple.com/join/Nn7iSOzY

Tap on the More tab in the iPhone app and then the Apple Watch Settings. On that screen you'll see a switch to either enable or disable workout activities. To demonstrate the issue, edit a timer to continue until manually stopped by changing the Number of Cycles to "Until Stopped". Then start the timer on the watch. Let it run for a period of time to create more than 50 intervals, for example, then stop the timer. Swipe to the leftmost screen on the watch, tap pause, then tap end. At that point you'll see how slow the workout saved.

Next, you can go back to the iPhone app, disable using workout activities and repeat the test. The workout will save quickly in this case.

I've filed a feedback.

I have an test app now using Apple's WWDC Watch Workout app sample code if anyone is interested.

I also have the same issue, do you have any fresh information ?

Finishing a HKLiveWorkoutBuilder workout with lots of HKWorkoutActivity instances is very slow
 
 
Q