EasyMapping/EasyMapping — pull request #49 by DenHeadless (2014-05-18 15:55:26+00:00)
Title: Core data import optimization

Ok, this was a long time coming =) This PR brings some support for big CoreData imports, using EasyMapping. Most of the work was already done by [Yuri Kotov](https://github.com/advantis) and [Dmitriy](https://github.com/poteryaysya) in Yalantis/FastEasyMapping fork, my job was to bring those features back without major API changes.

One change was really necessary, though. EKMapper was split into two classes, the second one - EKManagedObjectMapper to clearly differentiate between the two. All other public API remains unchanged.

To support CoreData imports, i added new class - EKCoreDataImporter. It basically does 3 things:

1. Collect array of entitities, that were passed to us in a form of NSDictionary or NSArray.
2. Introspect primary keys for all these entities.
3. When EKManagedObjectMapper needs a NSManagedObject subclass, make only one fetch request to get ALL collected entities back.

This way, it doesn't matter, how big our JSON is, we only make ONE fetch request for each entity. This approach is not bulletproof, though. If you create objects one by one, and don't use arrayOfObjects method, or don't use hasOne and hasMany relationships, you will not get any optimizations. I think i'll write separate piece about this in project's readme a bit later.

And finally, some results!

Benchmark | Before(sec) | After(sec)
--- | --- | ---
*Mac OS X* | 33.2 | 11.24
*iOS* | 28.81 | 11.42

Hardware used: Macbook Pro Retina 15" late-2013, iPhone 5.

@lucasmedeirosleite Can you please review changes and tell me what you think?