Re: [Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
That's very clear, thanks for the explanation! Aurélien, Objective Decision Team On 20 mai 09, at 21:15, Ben Trumbull wrote: 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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
re:[Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
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 (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
On Wed, May 20, 2009 at 8:25 AM, Aurélien Hugelé wrote: > There clearly is a difference since fetching is *much* slower that > objectWithID: then testing using try/catch is the object is a fault or not. Read the -[NSManagedObjectContext obtainPermanentIDsForObjects:error:] docs carefully: "This method results in a transaction with the underlying store which changes the file’s modification date." Think about that for a second. You're essentially saving the store to disk for each time you call -obtainPermanentIDsForObjects:error: (it's not really a "save" in the Core Data sense, but it is writing the store out to disk every time). Either batch all your requests up in one call to -obtainPermanentIdsForObjects:error:, or don't call it. --Kyle Sluder ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
There clearly is a difference since fetching is *much* slower that objectWithID: then testing using try/catch is the object is a fault or not. I'm puzzled... it works bout I would like to know the real difference here. Aurélien, Objective Decision Team On 20 mai 09, at 12:03, Aurélien Hugelé wrote: Hi list ! I have a subthread that sends to my main thread some objectIDs (of objects it inserted in the same store (same PSC)) I have 2 MOCs, one per thread, sharing the same PSC (following advices from the doc...) 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...) what does objectWithID: *exactly* do that a fetch does not ?? Thanks for your help. Aurelien Aurélien, Objective Decision Team ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/hugele.aurelien%40objective-decision.com This email sent to hugele.aurel...@objective-decision.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
Re: [Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
Hmmm, It seems I was using temporary objectIDs, not permanent ones... It was a nightmare with 10.4 because there was no way to get permanent objectIDs... now we can, and I've been overlooking that problem ;) Aurélien, Objective Decision Team On 20 mai 09, at 12:03, Aurélien Hugelé wrote: Hi list ! I have a subthread that sends to my main thread some objectIDs (of objects it inserted in the same store (same PSC)) I have 2 MOCs, one per thread, sharing the same PSC (following advices from the doc...) 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...) what does objectWithID: *exactly* do that a fetch does not ?? Thanks for your help. Aurelien Aurélien, Objective Decision Team ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/hugele.aurelien%40objective-decision.com This email sent to hugele.aurel...@objective-decision.com ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com
[Core Data] Difference between objectWithID: and a fetch "self IN %@", someObjectIDs ????
Hi list ! I have a subthread that sends to my main thread some objectIDs (of objects it inserted in the same store (same PSC)) I have 2 MOCs, one per thread, sharing the same PSC (following advices from the doc...) 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...) what does objectWithID: *exactly* do that a fetch does not ?? Thanks for your help. Aurelien Aurélien, Objective Decision Team ___ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com