离屏渲染 Offscreen rendering
Instruments
1、打开方式
打开Instruments.png图片.png
图片.png
2 触发方式
The biggest bottlenecks to graphics performance is offscreen rendering and blending – they can happen for every frame of the animation and can cause choppy scrolling.
Offscreen rendering (software rendering) happens when it is necessary to do the drawing in software (offscreen) before it can be handed over to the GPU. Hardware does not handles text rendering and advanced compositions with masks and shadows.
The following will trigger offscreen rendering:
-
Any layer with a mask (
layer.mask
) -
Any layer with
layer.masksToBounds
/view.clipsToBounds
being true -
Any layer with
layer.allowsGroupOpacity
set to YES andlayer.opacity
is less than 1.0
When does a view (or layer) require offscreen rendering? -
Any layer with a drop shadow (
layer.shadow*
).
Tips on how to fix: https://markpospesel.wordpress.com/tag/performance/ -
Any layer with
layer.shouldRasterize
being true -
Any layer with
layer.cornerRadius
,layer.edgeAntialiasingMask
,layer.allowsEdgeAntialiasing
-
Any layer with
layer.borderWith
andlayer.borderColor
?
Missing reference / proof -
Text (any kind, including
UILabel
,CATextLayer
,Core Text
, etc). -
Most of the drawing you do with
CGContext
indrawRect:
. Even an empty implementation will be rendered offscreen. -
阴影开启shadowPath wwdc 2014 session 419里有相应介绍