UIImageView displays MUCH faster than CG or CALayer. Does anyone know why?

I wrote an application for testing image performance on iOS. I tried 3 different views, all displayed the same large PNG. The first is a view that draws using CGContextDrawImage (). The second set is self.layer.content. The third is a simple UIImageView.

The image used is created using - [UIImage initWithContentsOfData:] and cached in viewController. Each test repeatedly selects a view, adds it to the view hierarchy, and then deletes it and releases it. Loading periods are executed from the beginning of loadView in viewDidAppear and are set as fps (efficiently, viewing pictures per second).

Here are the results from iPad 1 running on 5.1 using a 912 x 634 unscaled image:

CGContext: 11 fps CALayer: 10 fps UIImageView: 430 fps (!) 

Am I hallucinating? It seems almost impossible that a UIImageView can draw it quickly, but I can really see how the images flicker. I tried to exchange between two similar views in order to defeat possible caching, but the frame rate was even higher.

I always assumed that UIImageView was just a wrapper for - [CALayer setContent]. However, profiling UIImageView hardly spends time on any drawing method that I can identify.

I would like to understand what is happening. Any help would be most appreciated.

+8
ios core-graphics core-animation calayer uiimageview
source share
3 answers

Here is my idea.

When you change the hierarchy of a UIView by adding, deleting, or changing some view, the actual drawing is not yet executed. Instead, the view is marked with "setNeedsDisplay" and redrawn the next runloop.

Actually, if your test code looks something like this (I can only guess):

 for (int i=0; i<10000; i++) { UIImageView* imageView = [[UIImageView alloc] initWithFrame:frame]; [mainView addSubview: imageView]; [imageView setImage: image]; [mainView removeSubview: imageView]; } 

than runloop is blocked until this for loop is executed. The presentation hierarchy is drawn only once, the measured performance is the selection and initialization of objects.

On the other hand, CGContextDrawImage () can be drawn right away, I think.

+1
source share

The high FpS with UIImageView is that it doesn’t actually redraw, but sometimes it only notes content for redrawing in the future when UIKit feels that it does.

As a note: It is strange, however, that CGContextmethod is faster than CALayermethod. I also tried these methods in my project, and working with CALayer is the fastest method (except, of course, using OpenGL ES).

+1
source share

UIImageView uses a different way to render images, which is much more efficient. You should look at this video session from WWDC 2011, which explains how the rendering process works: https://developer.apple.com/videos/wwdc/2011/?id=121

0
source share

All Articles