github/Mantle — pull request #112 by steipete (2013-07-21 20:31:39+00:00)
Title: Add a cache for transformer objects.

[WIP] I've ported this from the various changes/tweaks in the PSPDFKit-Branch of Mantle. This isn't well-tested yet, but I'd like to hear opinions on it. We could cache all NSInvocation usages the same way (e.g. in `mergeValueForKey:fromModel:`), I just see the transformer calls as real hot spots. We will also need an additional test for CoreData.

In my tests this greatly speeds up serialization/deserialization. The transformer objects are cached instead of being created/deleted all the time. We also save time by not requiring the NSInvocation and building up the selector. This is thread safe as well since we atomically save the cache object; in the worst case we would look up transformers more than once.

Downside: The cache is saved on the class object, so it won't ever be cleaned up. I don't see this as an issue though as transformers usually are very small objects.