Performance Starting Point for iOS
When writing software for iOS, optimizing code to minimize use of the processors and memory is crucial to the performance of your application and therefore to a good user experience.
The main tool for analyzing your code’s use of the CPU, GPU, and memory is the Instruments application. Although you can do some optimization of your code using Simulator, you need to run your application on a physical device in order to determine how efficiently the CPU and GPU are being used. To learn how to set up your device for use with Instruments, see “Tuning Applications” in iOS Development Guide.
Each of the tools in Instruments is documented in Instruments User Guide.
For a discussion of performance tuning for iOS, as well as a great deal of other information on programming for iOS, see iOS App Programming Guide.
Although written specifically for the Mac OS X operating system, the general principles discussed in Performance Overview apply to iOS as well.
For details on management of memory resources, see Memory Usage Performance Guidelines.
iOS has several frameworks for graphics and animation. The highest-performance graphics are provided by OpenGL ES, which communicates directly with the GPU. OpenGL ES is typically used by games and other applications that require complex graphics that must be rendered very quickly. If you are using OpenGL ES, see “Performance Guidelines” in OpenGL ES Programming Guide for iOS for techniques to optimize your graphics code.
To improve the performance of your networking code, read TN2152: Document Transfer Strategies.
The XMLPerformance sample project explores two approaches to parsing XML, focusing on performance with respect to speed, memory footprint, and user experience.
Here are some tips to maximize performance:
Avoid doing unnecessary work. Avoid computing anything until you are sure you actually need it.
Avoid spinlocks, polling, and other CPU-hogging techniques.
Use Core Animation and other GPU-intensive APIs sparingly. Use animation only if it provides a user benefit.
Reduce your memory footprint by minimizing the amount of data you keep in memory at any given time.
Consider memory-mapping large files instead of reading them into RAM. Doing so helps the system manage memory more efficiently.
Release or free any allocated memory as soon as you are done using it.
When practical, perform network requests in batches rather than one at a time.