I have a UIView
with several instances of a subclassed CAShapeLayer
added as sublayers to its layer property.
I am animating changes to the UIBezierPath
for each of these layers, which looks awesome and is performant, but hits ~90% CPU on the backboardd
process when I run it through Activity Monitor in Instruments.
How can I get more information about what's happening here? backboardd
is the behind-the-scenes rendering of Core Graphics / Core Animation stuff on the GPU, right? Is there support for further debugging in Instruments somewhere? Could I do something fancy with GCD to load backboardd
less?
EDIT: After escalating this to a TSI with Apple, they have confirmed that this is 'expected behavior' for this number of animated CAShapeLayers. Sigh. They did offer a suggestion at this link, which involves continually pausing and unpausing the animation to mimic a lower frame rate. (Since it's the calculations for each DisplayLink-locked animation frame that are slamming backboardd
)
-(void)pauseLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
-(void)resumeLayer:(CALayer*)layer {
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}
Finally, the nice Apple tech pointed out that animation framerate control "would make a decent API enhancement request, as an aside" — so I'm making one, and you should, too. :)
You need to try and isolate your problem. It sounds like your layer hierarchy isn't scaling well and is becoming too complicated.
Do you see the same CPU activity if you use less instances of the subclassed CAShapeLayer? Or if you try to perform less animations?