UIView self.layer.shouldRasterize = YES and performance issues

I would like to share my experience using the self.layer.shouldRasterize = YES; flag self.layer.shouldRasterize = YES; in UIViews.

I have a UIView class hierarchy that self.layer.shouldRasterize turned ON to improve scroll ( ) performance , all of them have STATIC approaches that are larger than the device screen ).

Today, in one of the subclasses, I used CAEmitterLayer to create good particle effects.

Performance is very poor , although the number of particles was really low (50 particles) .

What is the cause of this problem?

+10
performance ios5 caemitterlayer
Jul 17 2018-12-17T00:
source share
2 answers

I will just bring the Apple Doc and explain:

 @property BOOL shouldRasterize 

When the value of this property is YES, this layer is equally rendered as a bitmap in the local coordinate space, and then compiled to the destination with any other content. Shadow effects and any filters in the filter property are rasterized and included in the bitmap. However, the current opacity of the layer is not rasterized. If the rasterized bitmap needs to be scaled during layout, the filters in the minificationFilter and magnificationFilter properties are applied as needed.

So basically, when the isRasterize parameter is set to YES, each pixel that will make up the layer is computed, and the entire layer is cached as a bitmap.

  • When will you benefit from this?

When you only need to draw it once. This means that you just need a โ€œsimpleโ€ animation (like moving, transforming, scaling ...), because CoreAnimation will use this layer without redrawing each frame. This is a very powerful feature for caching complex layers (with shadows and angular radius) in combination with CoreAnimation.

  • When will he kill you in frame rate?

When your layer is re-rendered many times because at the top of the drawing, which is already taking effect, shouldRasterize will process all the pixels to cache the bitmap image data.

So, the real question that you should ask yourself is: "On which layer do I apply shouldRasterize to YES? And how often does this layer redraw?"

Hope this was clear enough.

+31
Jul 17 '12 at 12:35
source share

Disabling self.layer.shouldRasterize improves performance to a normal level.

Why is this?

According to the video on the Apple developers site (I canโ€™t remember the video, please help?) The rule for self.layer.shouldRasterize is so simple: if all your subzones are static (their position, contents, etc., are not changing or animation ), then the beneficiary needs to enable self.layer.shouldRasterize ON. On the other hand, if any of the subzones changes, then the infrastructure needs to re-cache the hierarchy of views, and this is a huge bottleneck. Under the hood, a bottleneck is copying memory between the processor and the GPU.

+10
Jul 17 2018-12-12T00:
source share



All Articles