IOS: will use [UIImage -imageNamed:] without a file extension causing performance problems?

I have an image named image@2x.png . 1 KB file. My application is an application for the iPhone.

I upload the image to my application with this call:

 [UIImage imageNamed:@"image"]; 

When using the I / O activity tool that analyzes I / O actions, I found that there are several actions associated with this file that lead to the error "There is no such file or directory", and these actions take some time.

these actions are similar to reading these files:

 image_2_only_@2x~iphone.png image@2x~iphone.png image@2x.png (this one doesn't fail) 

And, to my surprise, each failed operation takes longer than one of them.

How can I avoid such a performance issue?

+8
performance ios iphone uiimage
source share
1 answer

If you want to prevent extended access to the file system, do not use [UIImage imageNamed:] , but [UIImage imageWithContentsOfFile:] .

The latter will not make automated image selection (guessing, guessing the retina, etc.) and will not use memory caching.

Make sure that you remember that any duplicate access to the image in the file system will, when using my proposal, be punished very hard.

I do not recommend not using imageNamed: to improve application performance. Usually the opposite is true, and when using this method, image loading will be more optimized (caching). However, as soon as you are sure that a particular image will not be downloaded again and to prevent excessive search in the file system, use imageWithContentsOfFile: In addition, it is actually recommended to use imageWithContentsOfFile: when the memory usage is a point - no caching means that the memory has less latency.

+5
source share

All Articles