• 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
re:[Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

re:[Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????


  • Subject: re:[Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
  • From: Ben Trumbull <email@hidden>
  • Date: Wed, 20 May 2009 12:15:32 -0700

In the main thread, using objectWithID: repeatedly on each objectID
sent by the subthread returns the object that was inserted in the
background thread. This is exactly what I want.
But reading from the doc, it seems that we are encouraged to use a
fetch using "self IN %@",listOfObjectIDs instead of objectWithID:
since it is faster for many objects...

Unfortunately, this fetch returns 0 results (and yes this is the
correct entity, store and moc...)

The objects probably haven't been saved yet.

what does objectWithID: *exactly* do that a fetch does not ??

Imagine the NSPersistentStoreCoordinator has a cache of row data for recently fetched or saved objects. This cache is used to fulfill faults quickly. Faulting becomes very slow when it needs to go all the way to the database due to a cache miss. The Core Data template in Instruments shows this.


But cache hits are very fast. This is how most managed objects get initialized.

Fetching always goes to disk and gets the latest values from the database. Those values are then added to the PSC's cache.

-objectWithID: creates a fault. When you access the fault's data, it first tries to populate the data from the PSC's cache. If it can't, then it goes to disk.

The documentation is showing how to load a number of objects at once. If the objects are unlikely to already be cached, then fetching all of them in 1 transaction will be much faster than faulting them in one at a time via -objectWithID:

- Ben

_______________________________________________

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] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
      • From: AurĂ©lien HugelĂ© <email@hidden>
  • Prev by Date: Re: CGRectUnion with one empty Rectangle
  • Next by Date: Re: Sensible way to extend base class?
  • Previous by thread: [moderator] thread closed -- Re: [OT] Anyone have the a DIRECT phone number for a real person at Apple Legal???
  • Next by thread: Re: [Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
  • Index(es):
    • Date
    • Thread