3
votes

i have a performance Problem, if i load an JPG (and yes i can't provide any PNG File Format in the App) Image from the Disk with [UIImage imageWithContentsOfFile: ], store the UIImage in a global NSCache and use the Cached Image in [UITableViewCell drawRect: ]. This approach is much slower than user [UIImage imagedNamed:] .

If have analyzed the performance with the Instruments "Time Profile" and as you can see in the first picture the JPEG is always decode in the [DBArtistTableViewCell drawRect:]. In the second picture with the [UIImage imageNamed:] solution the JPG will not decompressed.

NSCache + UIImage Solution: NSCache + UIImage

[UIImage imageNamed] Solution UIImage imageNamed

The short question is: Why is the UIImage + NSCache solution slower than the [UIImage imageNamed:] solution and what is the magic with [UIImage imageNamed:] Method (yes i know the caching, but what is the rest of the magic) ?

Thx for Helping.

1

1 Answers

3
votes

I believe the reason is that UIImage imageNamed causes the data to be decompressed and stored in it's cache, whereas UIImage imageWithContentsOfFile loads the compressed data, but doesn't decompress it until you need to display it.