Note that there are some explanatory texts on larger screens.

plurals
  1. POSlow deletes and saves in nested NSManagedObjectContext
    primarykey
    data
    text
    <p>In my app I have a "master" <code>NSPrivateQueueConcurrencyType</code> context which serves as a parent to a <code>NSMainQueueConcurrencyType</code> context that the view controller's rely on and pass around. I wanted to do this to take advantage of async saves (this app uses iCloud with Core Data and saves do a lot of work exporting ubiquity logs). The setup is similar to the Zarra approach mentioned at the bottom of <a href="http://www.cocoanetics.com/2012/07/multi-context-coredata/" rel="noreferrer">this article</a></p> <p>Saves within the app typically look like:</p> <pre><code>[context save:nil]; [context.parentContext performBlock:^{ [context.parentContext save:nil]; }]; </code></pre> <p>This seems to work well for small edits/updates, but I'm confused about what I see when I delete many objects (eg, delete a project that has hundreds of task objects related to it).</p> <p>In that situation the save is async but it looks like the main thread gets into a semaphore wait situation (as seen when I pause the debugger) and is effectively blocked (I can't scroll in the UI) until the background private context finishes the save.</p> <p>Actually, I just noticed that swipe-to-delete deletions of a single object incur a noticeable delay, despite this async save pattern, so it seems all deletions in the app are slow.</p> <p>If, alternatively, I alloc a new <code>NSPrivateQueueConcurrencyType</code> context, set its persistent store coordinator to the main PSC in the AppDelegate, and perform the delete and save, it still does a lot of work but the UI is never blocked (but then I have to worry about coordinating the contexts, refetching in the main context).</p> <p>Any ideas what I might have done wrong, or have you seen this behavior also?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload