my iPhone application has a Words object with the attributes word , length and language . Both are indexed: 
I copied cdatamodel and the database to a separate importer application, where it got pre-populated with approximately 400 kilograms of words in different languages. I checked the import by looking at the SQLite file, and then copied the pre-populated database back to the iPhone project.
At first, I thought that the predicate (simple) is a problem. But even after removing the predicate from the query, it takes a very long time to complete:
2011-09-01 09:26:38.945 MyApp[3474:3c07] Start 2011-09-01 09:26:58.120 MyApp[3474:3c07] End
This is what my code looks like:
// Get word NSLog(@"Start"); NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Words" inManagedObjectContext:appDelegate.managedObjectContext]; [fetchRequest setEntity:entity]; NSError *error = nil; NSArray *fetchedObjects = [appDelegate.managedObjectContext executeFetchRequest:fetchRequest error:&error]; if (fetchedObjects == nil) { //... error handling code } [fetchRequest release]; NSLog(@"End"); return fetchedObjects;
Is the number of records in the database a problem for master data?
EDIT : As pointed out by gbbrรผckmann and jrturton, it is nice to set fetchBatchSize . But the receiving time is still unsatisfactory:
2 seconds with a set of predicates:
NSPredicate * predicate = [NSPredicate predicateWithFormat: @ "length ==% d And the language is BEGINSWITH% @", wordLength, lng]; [fetchRequest setPredicate: predicate];
7 seconds with a set batch size:
[fetchRequest setFetchBatchSize: 1];
1 second indicating both the predicate and batch size
Is there another bottleneck?
Norbert
source share