Graphics Reference
In-Depth Information
Figure 14.2 The Time Profiler instrument showing the CPU bottleneck
The only way to improve the performance here is to move the image loading onto another
thread. This won't help to reduce the actual loading time (it might even make it slightly
worse, because the system will potentially be devoting a smaller slice of CPU time to
processing the loaded image data), but it means that the main thread can continue doing
other things, like responding to user input and animating the scroll.
To load the images on a background thread, we can either create our own threaded loading
solution using CGD or NSOperationQueue , or we can use CATiledLayer . To load images
from a remote network, we could use an asynchronous NSURLConnection , but that's not a
very efficient option for locally stored files.
GCD and NSOperationQueue
GCD (Grand Central Dispatch) and NSOperationQueue are similar in that they both allow
us to queue blocks to be executed sequentially on a thread. NSOperationQueue has an
Objective-C interface (as opposed to the global C functions used by GCD) and provides
fine-grained control over operation prioritization and dependencies, but requires a bit more
setup code.
Search WWH ::




Custom Search