Graphics Reference
In-Depth Information
14
Image IO
The idea of latency is worth thinking about.
Kevin Patterson
In Chapter 13, “Efficient Drawing,” we looked at performance issues relating to Core
Graphics drawing and how to fix them. Closely related to drawing performance is image
performance. In this chapter, we investigate how to optimize the loading and display of
images from the flash drive or over a network connection.
Loading and Latency
The time taken to actually draw an image is not usually the limiting factor when it comes to
performance. Images consume a lot of memory, and it may be impractical to keep all the
images that your app needs to display loaded in memory at once, meaning that you will
need to periodically load and unload images while the app is running.
The speed at which an image file can be loaded is limited not only by the CPU but also by
IO (Input/Output) latency. The flash storage in an iOS device is faster than a traditional
hard disk, but still around 200 times slower than RAM, making it essential that you manage
loading carefully to avoid noticeable delays.
Whenever possible, try to load images at inconspicuous times in your application's
lifecycle, such as at launch, or between screen transitions. The maximum comfortable delay
between pressing a button and seeing a reaction onscreen is around 200ms—much more
than the ~16ms between animation frames. You can get away with taking even more time
to load your images when the app first starts up, but the iOS watchdog timer will terminate
your app if it doesn't start within 20 seconds (and users won't be impressed if it takes more
than 2 or 3).
 
 
Search WWH ::




Custom Search