RestKit/RKValueTransformers — pull request #14 by carllindberg (2014-10-29 00:04:18+00:00)
Title: Add a cache in RKCompoundValueTransformer

This PR adds a cache in RKCompoundValueTransformer for source/destination class pairs, so that the subset of matching transformers does not have to be calculated every time. This is a significant time savings while mapping.

This is the largest bottleneck I came across while looking into performance issues noted at https://github.com/RestKit/RestKit/issues/2065 . When using the test application posted at https://github.com/rtimpone/restkit_relationship_mapping_benchmarking , I get the following timings on my device and iOS simulator (timings in seconds):

(Device) Mapping 5000 students with relationship mapping: 54.088767
(Simulator) Mapping 5000 students with relationship mapping: 7.312836

After applying this fix, the results are now more like:

(Device) Mapping 5000 students with relationship mapping: 43.592469
(Simulator) Mapping 5000 students with relationship mapping: 5.629380

I did play with using pthread_rw_locks, and the performance was comparable. dispatch queues were more variable, but the average seemed about the same, so I left in the queue implementation. A \@synchonized block was also similar, but that becomes more of a contention point if there are concurrent mapping operations, since the default RKCompoundValueTransformer is shared.

This was one of the bottlenecks mentioned at http://stackoverflow.com/questions/25431010/restkit-nested-one-to-many-relationship-mapping-is-very-slow , so others have noticed it too.