Graphics Reference
In-Depth Information
return cell;
}
@end
Much better! There is still some pop-in if we scroll very quickly, but for normal scrolling
it's now pretty rare, and the caching means that we're doing less loading anyway. Our
preloading logic is very crude at the moment, and could be improved by taking into account
the scroll speed and direction of the carousel, but it's already substantially better than our
uncached version.
File Format
Image loading performance depends crucially on a tradeoff between the time taken to load
a larger image file format and the time taken to decompress a smaller one. A lot of Apple
documentation still states that PNG is the preferred format for all images on iOS, but this is
outdated information and grossly misleading.
The lossless compression algorithm used by PNG images allows slightly faster
decompression than the more complex lossy algorithm used for JPEG images, but this
difference is usually dwarfed by the difference in loading time due to (relatively slow) flash
storage access latency.
Listing 14.6 contains the code for a simple benchmarking app that loads images at various
sizes and displays the time taken. To ensure a fair test, we measure the combined loading
and drawing time of each image to ensure that the decompression performance of the
resultant image is also taken into account. We also load and draw each image repeatedly for
a duration of at least one second so that we can take the average loading time for a more
accurate reading.
Listing 14.6 A Simple Image Loading Performance Benchmarking App
#import "ViewController.h"
static NSString * const ImageFolder = @"Coast Photos" ;
@interface ViewController () < UITableViewDataSource >
@property ( nonatomic , copy ) NSArray *items;
@property ( nonatomic , weak ) IBOutlet UITableView *tableView;
@end
 
Search WWH ::




Custom Search