A little goes a long way: NSOperations
While putting together a prototype that pulls a feed of interesting pics from flickr and have them displayed as a carousel on a UIScrollView, I was baffled by the unusual length of time it took for the scrollview to render, even in the simulator. The delay, especially when combined with the use of a UINavigationController, was downright unacceptable.
Check out this vid to get a taste:
It took only one look from a veteran objective-c developer colleague to diagnose the problem – UINavigationController was waiting for a single thread to finish rendering all 60 images before sliding in the ScrollView. “NSInvocationOperation is your answer“, he said.
And indeed it was, the perceived performance sky rocketed ten folds after the process of initializing UIImages was wrapped in an NSOperation. Here’s the difference:
And the code change was as follows:
Basically, all that was required was to move the necessary rendering logic to a separate method, create instances of NSOperations with selectors set to the method, and add those NSOperations into the NSOperationQueue. The Queue would schedule the firing of these operations and there wouldn’t be any hint of sluggishness at the UI. Thread programming 101. Duh.
Extended Reading:

