Graphics Reference
In-Depth Information
12
Tuning for Speed
Code should run as fast as necessary, but no faster.
Richard E. Pattis
In Parts I and II, we learned about the awesome drawing and animation features that Core
Animation has to offer. Core Animation is powerful and fast, but it's also easy to use
inefficiently if you're not clear what's going on behind the scenes. There is an art to getting
the best performance out of it. In this chapter, we explore some of the reasons why your
animations might run slowly and how you can diagnose and fix problems.
CPU Versus GPU
There are two types of processor involved in drawing and animation: The CPU (central
processing unit) and GPU (graphics processing unit). On modern iOS devices, these are
both programmable chips that can run (more or less) arbitrary software, but for historical
reasons, we tend to say that the part of the work that is performed by the CPU is done “in
software” and the part handled by the GPU is done “in hardware.”
Generally speaking, we can do anything in software (using the CPU), but for graphics
processing, it's usually much faster to use hardware because the GPU is optimized for the
sort of highly parallel floating point math used in graphics. For this reason, we ideally want
to offload as much of our screen rendering to hardware as possible. The problem is that the
GPU does not have unlimited processing power, and once it's already being used to full
capacity, performance will start to degrade (even if the CPU is not being fully utilized).
Most animation performance optimization is about intelligently utilizing the GPU and CPU
so that neither is overstretched. To do that, we first have to understand how Core Animation
divides the work between these processors.
 
 
Search WWH ::




Custom Search