I have an app for iPhone / iPad that uses Core Data.
In my database, I have only one table, although it is very large (about 40 columns). When I create a database, I create and insert about 13,000 new entities, and then I call "saveContext".
for (NSArray *singleDiamond in allDiamonds) { @try { if (//Some validation) { Diamond *diamond = [NSEntityDescription insertNewObjectForEntityForName:NSStringFromClass([Diamond class]) inManagedObjectContext:self.managedObjectContext]; //Do setup for diamond... } } @catch (NSException *exception) {NSLog(@"%@",[exception message]);} } NSLog(@"Start Saving Context..."); [self saveContext]; NSLog(@"End Saving Context...");
The identifier of my problem is that only the saveContext method takes 23 seconds . This is unacceptable.
Is there something I'm doing wrong? How can I improve performance here?
source share