Contexts and Syncing

In Vesper Sync Diary #2 I wrote:

I set up two NSManagedObject​Contexts: one on the main thread and one with private queue concurrency. The main thread context is the child of the private queue context.

This way, doing a save on the main thread doesn’t hit the database: changes get saved to the private queue context, which then does a save to the database.

This agrees with Matt Drance’s advice yesterday:

For ongoing sync, you should consider a private queue parent context w/ main queue as child.

There’s just one thing that worries me about this, and it’s Florian Kugler’s Performance Shootout, where he found that independent contexts spend far less time on the main thread.

But it should be noted that his performance shootout doesn’t include this particular configuration, with parent as the background context and child as the main thread context.

So… I think that my setup should perform fine. It’s the one Matt suggests. But I’m still at the point where I look at each of my decisions critically.

If you — who have more Core Data experience than I do — know of a good reason not to set up my contexts as private/parent and main/child, please let me know on Twitter.

26 Feb 2014

Archive