Looking at the Instruments snapshot, one can see most of the time is
spent maintaining the inverse relationship as that is triggering
faulting of unloaded data.
When you dirty a managed object for the first time, we need its
current data to establish a snapshot. The snapshot is used for
several features including undo, merge policies & conflict
detection, and the committedValuesForKeys/changedValues methods.
This includes the identities (but not full data) of object's current
For to-many relationships, this can trigger additional faulting (in
database terms, a fetch against the join table)
You can address the problem by prefetching Foo's to-many
relationships during your initial fetch. If Bar has other to-many
relationships, you'll want to prefetch those in the fetch request
for "bar where ID = X"
The Instruments set you used doesn't include all the Core Data
instruments from the main template, specifically "Core Data Cache
Misses", so Instruments isn't high lighting the specific problem as
well as it could.
If you add that instrument, you should see both the entity and
relationships that are being faulted.
Thanks Ben. I'll take your comments on board and see if I can't speed