Building Automated Analytics Logging for iOS Apps
blog.heapanalytics.com
blog.heapanalytics.com
It may indeed be a negligible impact as they claim, but using the Time Profiler instrument they could show exactly how much time is spent in the main queue on their swizzled code which would be a much better indication of whether or not the performance impact is negligible than eyeballing a cpu utilization graph.
It's certainly worth displaying the time spent in the replacement method call using the Time Profiler.
At the very least, it should be trivial to confirm that CPU usage is low by checking out this code (or installing Heap) and running Time Profiler yourself.
Which is fine if you're adding automatic event-tracking directly to your own app. But for a third-party library (like our own), it exacerbates the integration process. Method swizzling allows for a purely drop-in solution.
For example, you lost me. Having stumbled on it, I couldn't bring myself to finish the piece. I actually do need an analytics solution for our iOS app, but this blog post just fell into "I will read it later" category, out of "I will read it now".
Noted, though, that we lost you with the piece's verbosity.
The actual method exchange (#1) is little more than a pointer swap and happens at load time. You can safely assume it introduces no performance overhead.
The overhead of swizzled code (#2) is also minimal. Specifically, in Instruments you'll see that ~1ms of time gets spent in an empty replacement method before the original method is called. But this replacement method is blocking, so it's imperative you keep it as lean as possible (e.g. by pushing tasks onto a background queue).
Many Cocoa/Cocoa Touch APIs (NSDictionary, UIButton, etc) recommend composition over subclassing, so you'll often see people do things like add a category or swizzle methods.
I've done a little method swizzling myself, but it makes me a little nervous about side effects, so I try to only use that technique as a very last resort.
I think what they're doing here is pretty clever, but I would be uneasy about using it in a shipped app.