3lvis / DATAStack

100% Swift Simple Boilerplate Free Core Data Stack. NSPersistentContainer
Other
214 stars 44 forks source link

mergeChangesFromContextDidSaveNotification performance #57

Closed 3lvis closed 8 years ago

3lvis commented 8 years ago

When mergeChangesFromContextDidSaveNotification happens with non faulted objects _newChangedValuesForRefresh__ gets called to fault the objects before merging them, this could be happening on the main thread so it could help to do the following loop in order to bring faulted objects before performing the merge.

NSArray* objects = [notification.userInfo valueForKey:NSUpdatedObjectsKey];
for (NSManagedObject* obj in objects) {
    NSManagedObject* mainThreadObject = [mainContext objectWithID:obj.objectID];
    [mainThreadObject willAccessValueForKey:nil];
}
3lvis commented 8 years ago

Tried this, haven't found any performance improvements. I'll try batching next.

3lvis commented 8 years ago

Related to https://github.com/hyperoslo/Sync/issues/217

3lvis commented 8 years ago

Fixed on https://github.com/SyncDB/Performance

3lvis commented 8 years ago

Basically the solution is to use newNonMergingBackgroundContext