Graphics Reference
In-Depth Information
13
Efficient Drawing
More computing sins are committed in the name of efficiency (without necessarily achieving it) than for
any other single reason—including blind stupidity.
William Allan Wulf
In Chapter 12, “Tuning for Speed,” we looked at how to diagnose Core Animation
performance problems using Instruments. There are many potential performance pitfalls
when building iOS apps, but in this chapter, we focus on issues relating specifically to
drawing performance.
Software Drawing
The term drawing is usually used in the context of Core Animation to mean software
drawing (that is, drawing that is not GPU assisted). Software drawing in iOS is done
primarily using the Core Graphics framework, and while sometimes necessary, it's really
slow compared to the hardware accelerated rendering and compositing performed by Core
Animation and OpenGL.
In addition to being slow, software drawing requires a lot of memory. A CALayer requires
relatively little memory by itself; it is only the backing image that takes up any significant
space in RAM. Even if you assign an image to the contents property directly, it won't use
any additional memory beyond that required for storing a single (uncompressed) copy of
the image; and if the same image is used as the contents for multiple layers, that memory
will be shared between them, not duplicated.
But as soon as you implement the CALayerDelegate -drawLayer:inContext: method or
the UIView -drawRect: method (the latter of which is just a wrapper around the former), an
offscreen drawing context is created for the layer, and that context requires an amount of
 
 
Search WWH ::




Custom Search