iOS Nested Context slower on Device [on hold]

I’m trying to move from one NSManagedContext to multiple via nested context.

I’m using those article to help me :

Actual System

[myHTTPClient getPath:path
  parameters:@{access_token & stuff}
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    for (NSDictionary *dictionary in responseObject)
    {
      // filling the dic in a NSManagedObject
    }
    [myMainContext save:&error];
  }, failure:failureBlock];

Wanted System

[myHTTPClient getPath:path
  parameters:@{access_token & stuff}
  success:^(AFHTTPRequestOperation *operation, id responseObject) {
    __block NSManagedObjectContext *managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
    __block NSManagedObjectContext *writerObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] writerManagedObjectContext];
    __block NSManagedObjectContext *temporaryContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
    temporaryContext.parentContext = managedObjectContext;
    NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];

    [temporaryContext performBlock:^{
      for (NSDictionary *dictionary in responseObject)
      {
        // filling the dic in a NSManagedObject
      }
      [temporaryContext save:&error];
      [managedObjectContext performBlock:^{
        [managedObjectContext save:&error];
        [writerObjectContext performBlock:^{
          [writerObjectContext save:&error];
        }];
      }];
    }];
  }, failure:failureBlock];

Diagram

Parent-Context Diagram

Problem

I had problems saving my data while using this method but I solved it (cf. CoreData – writerManagedObjectContext freeze when save)

However, as I said in the previous question, it speed up 2 times on the simulator but it’s like 5x slower on a device. I use iPod Touch 4th to test.

How is it possible and how can I improve that ?
I’m not against using this diagram :

Shared Persistent Store Diagram

But I want to find out HOW to integrate that in my code because I tried and it changed nothing.

Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>