CloudKit initial sync and background audio leads to high CPU app termination

I have a music app that can play in the background, using AVQueuePlayer. I'm in the process of adding support for CloudKit sync of the CoreData store, switching from NSPersistentContainer to NSPersistentCloudKitContainer.

The initial sync can be fairly large (10,000+ records), depending on how much the user has used the app. The issue I'm seeing is this:

  • ✅ When the app is in the foreground, CloudKit sync uses a lot of CPU, nearly 100% for a long time (this is expected during the initial sync).

  • ✅ If I AM NOT playing music, when I put the app in the background, CloudKit sync eventually stops syncing until I bring the app to the foreground again (this is also expected).

  • ❌ If I AM playing music, when I put the app in the background, CloudKit never stops syncing, which leads the system to terminate the app after a certain amount of time due to high CPU usage.

Is there any way to pause the CloudKit sync when the app is in the background or is there any way to mitigate this?

Replies

Here's a CPU capture of the different states.

Most likely the same problem as here: https://developer.apple.com/forums/thread/687877

Me and other people with large core data store (and lot of relations) have been waiting since iOS 15 beta 4 for it to be fixed

Let's hope it's fixed on iOS 15.1

  • Yeah I saw that thread, but wasn't sure if it was related since it only seems to happen for me when I have music playing. I didn't see the same memory spike (the memory usage actually seemed pretty reasonable in my test), but the symptoms definitely sound similar.

    I tested this on 15.1b4.

  • The number of relation seem to be the root of the problem, perhaps you don't have enough relation to prevent sync to happen almost correctly until audio kick in, let's hope an engineer pass by 😅.

    Are you sure it's really syncing ? In my case after a backup restore sync start, and I can see it start on another device, but never finish (probably 10.000+ records with lots of relationships with them)

Add a Comment

I've had the exact same problem, except running in background recording location updates. In the end I had to disable Core Data Cloud Kit sync. Was this ever fixed?