my iPhone application has an entity Words
with the attributes word
, length
and language
. Both are indexed:
I copied the cdatamodel and database to a separate importer application where it got prefilled with about 400k words in different languages. I verified the import by looking into the SQLite file and then copied the prefilled database back to the iPhone project.
First I thought the (simple) predicate is the problem. But even after deleting the predicate from the fetch request, it takes a very long time for execution:
2011-09-01 09:26:38.945 MyApp[3474:3c07] Start
2011-09-01 09:26:58.120 MyApp[3474:3c07] End
Here 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 entries in the database a problem for Core Data?
EDIT:
As gcbrueckmann and jrturton pointed out, it's a good point to set fetchBatchSize
. But fetch time is still unsatisfying:
2 seconds with a predicate set:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"length == %d AND language BEGINSWITH %@", wordLength, lng]; [fetchRequest setPredicate:predicate];
7 seconds with the batch size set:
[fetchRequest setFetchBatchSize:1];
1 second with a both the predicate and the batch size set
Is there still another bottleneck?