In iOS UIImage image loading performance analysis, the performance of loading images in 3 was analyzed, but after subsequent research and search, it was found that the analysis in the previous article was not very comprehensive.

The whole image loading includes two processes, the first is the image resource loading, in the article compared to the performance is actually the resource loading performance; The second is the decoding of image resources. The following figure is the timer profile statistical result of the image loading method.

1. Load the Asset image resource



2.[UIImage imageNamed:] loads the logical directory resource



3.[UIImage imageWithContentsOfFile:] Loads logical directory resources



The statistical results

Loading image mode It takes time to load image resources Image decoding time
Loading Asset Resources 59 37
[UIImage imageNamed:] loads the logical directory resource 413 155
[Uiimage imageWithContentsOfFile:] Loads the logical directory resource 123 155

Comparing methods 2 and 3, it is found that the decoding time of image resources is the same between the two methods, while the loading time of Asset is very small, indicating that Apple not only optimized the resource time on Asset, but also did a lot of work on the resource codec, and the decoding performance was improved to 23%.

Image = imageView.image= imageview. image= imageview. image= imageview. image=image There are ways on the network to put the decoding on other threads, mainly by drawing the image on the bitContext and then reading the image.