CALayer optimization?

I add several CALayers as sublayers of the UIView layer. The content of each layer is a different image downloaded from the server. Each layer is animated from the screen to a randomly generated position. Image data is loaded asynchronously. Each image is approximately 300x300 or less.

As a result of random placement, the layers overlap, and some are obscured by layers above them. This is all good.

I delete the layers as they completely close the view using the sentence answer to this question . Calculations to determine coverage occur in a separate stream.

I have a UIPanGestureRecognizer that allows the user to drag and drop layers around the screen.

I ran into a performance issue when the number of layers added approaches 25-30 and it gets worse. Animation becomes volatile and often completely absent (recently added layers just appear in their final position). And panorama gestures are either ignored or result in a mutable movement of the selected layer.

Am I assuming I'm killing a GPU with all overlapping layers and another animation layer above?

Any suggestions on how to improve performance?

Recommendations for working with a large number of layers?

Is it better to start animating a layer in a separate view than previously added layers?

Thanks!

+7
source share
2 answers

A few quick things to check.

Run the Core Animation tool and find the opacity. Simply setting the opaque flag level to YES is not enough if there is an alpha component in the base image, this layer will take this into account.

If the data you receive from your server is alpha, then you should redraw using Quartz and save the file locally in a new format that does not include alpha.

Make doubly sure that you do not put 1 megapixel image in 100x100 plates. Also Core Animation Instrument by turning on โ€œColor Inconsistent Imagesโ€ and look for yellow.

From 30 to 50 layers should not be a problem.

+4
source

If all layers do not fit into the memory or part of the GPU memory, everything will slow down. It is reported that loading and unloading GPU memory is quite slow compared to the layout layers in the GPU memory. You will have to experiment with this memory limit, as older devices have less GPU memory than more modern devices.

+3
source

All Articles