• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Core Data fetch performance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Core Data fetch performance
      • From: Hunter Hillegas <email@hidden>
  • Prev by Date: Display alert sheet when application is not active
  • Next by Date: Re: Display alert sheet when application is not active
  • Previous by thread: Re: Display alert sheet when application is not active
  • Next by thread: Re: Core Data fetch performance
  • Index(es):
    • Date
    • Thread