magicalpanda/MagicalRecord — pull request #588 by seepel (2013-10-13 23:02:41+00:00)
Title: Data Import Performance Improvements

This is a starting point, and open for discussion pull request regarding issue #450.

WARNING: I haven't run any unit tests on my changes. I remember it used to be pretty straight forward, but I just wasn't sure how to do it. Probably should be done before merging, I'm open to any pointers.

The main gist of this pull request is to cut down on the number of fetches required (especially when importing to-many relationships). With these changes I see ~3-4x improvement on large imports with nested to-many relationships.

Main changes:
- Import from array fetches in batch, this trades off some memory for performance improvements.
- Check to see if values need to be update before setting them. If there are no actual changes is content and the NSManagedObject gets touched, Xcode updates it's version number resulting in many UPDATE statements

Finally, another ~3-4x performance improvement can be made by not calling MR_swapMethodsFromClass on every single object. I didn't quite grasp the reason for swapping back and forth all the time, so I didn't change it here.