Core Data fetch performance
Core Data fetch performance
- Subject: Core Data fetch performance
- From: Rick Mann <email@hidden>
- Date: Sun, 11 Nov 2012 06:42:47 -0800
I'm seeing a substantial degradation in Core Data fetch performance after just a few thousand objects, in the simulator on a beefy MacBook Pro.
My app loads data from the web, then uses an integer key in each downloaded record to find the local record in Core Data. So I do a lot of queries like this:
{
NSFetchRequest* req = [[NSFetchRequest alloc] init];
req.fetchLimit = 1;
NSManagedObjectContext* moc = self.managedObjectContext;
NSEntityDescription* entity = [NSEntityDescription entityForName: @"MissionEvent"
inManagedObjectContext: moc];
req.entity = entity;
NSPredicate* pred = [NSPredicate predicateWithFormat: @"keyShadow == %ld", inMEP.mId];
req.predicate = pred;
NSError* error = nil;
NSArray* events = [self.managedObjectContext executeFetchRequest: req error: &error];
...
}
Basically, I query, the insert, over and over. As the number of records grows from 0 to 6000, the time it takes to execute this query grows from about 0.0007 s to about 0.0126 s. Indexing is on for keyShadow:
sqlite> explain query plan SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCLOCKSHADOW, t0.ZDESC, t0.ZDISABLEDSHADOW, t0.ZDURATIONSHADOW, t0.ZKEYSHADOW, t0.ZLASTMODIFIED, t0.ZNAME, t0.ZSEQUENCESHADOW, t0.ZTIMESHADOW, t0.ZTYPESHADOW, t0.ZMISSION FROM ZMISSIONEVENT t0 WHERE t0.ZKEYSHADOW = ?
...> ;
sele order from deta
---- ------------- ---- ----
0 0 0 SEARCH TABLE ZMISSIONEVENT AS t0 USING INDEX ZMISSIONEVENT_ZKEYSHADOW_INDEX (ZKEYSHADOW=?) (~10 rows)
This seems like pretty poor performance. Is this the best I can hope for?
Thanks,
--
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden