iOS Reference Library Apple Developer
Search

Tuning Applications

Optimizing your application’s performance is an important phase of the development process, more so in iOS-based devices, which, although powerful computing devices, do not have the memory or CPU power that desktop or portable computers possess. You also have to pay attention to your application’s battery use, as it directly impacts your customer’s battery-life experience.

This chapter describes Instruments and Shark, the tools you use to measure and tune your application’s performance.

Prerequisites: Follow the instructions in ‚ÄúRunning Applications‚Äù before trying the application-tuning techniques described in this chapter on your application.

For general performance guidelines, see iOS Application Programming Guide.

The Instruments Application

The Instruments application lets you gather a variety of application performance metrics, such as memory and network use. You can gather data from iOS applications running in iPhone Simulator or on your development devices.

It is important that your iOS applications use the resources of iOS-based devices as efficiently as possible to provide a satisfactory experience for you customers. For example, your application should not use resources in a way that makes the application feel sluggish to users or drains their batteries too quickly. Applications that use too much memory run slowly. Applications that rely on the network for their operation must use it as sparingly as possible because powering up the radios for network communications is a significant drag on the battery.

The Instruments application provides an advanced data gathering interface that lets you know exactly how your application uses resources, such as the CPU, memory, file system, and so on.

Instruments uses software-based data-gathering tools, known as instruments, to collect performance data. An instrument collects a specific type of data, such as network activity or memory usage. You find which instruments are available for iOS in the Instruments Library.

Although most iOS applications run in iPhone Simulator and you can test most design decisions there, the simulator does not emulate a device, in particular it doesn’t attempt to replicate a device’s performance characteristics such as CPU speed or memory throughput. To effectively measure your application’s performance as users may use it on their devices, you must use an iPhone or iPod touch. That’s because only on a device can you get an accurate representation of the runtime environment (in terms of processor speed, memory limitations, specialized hardware, and the like).

These are some limitations of iPhone Simulator:

To measure your application’s performance on a device:

  1. Build and run your application on the device as described in “Running Applications.”

  2. Launch Instruments.

    The Instruments application is located at <Xcode>/Applications. (<Xcode> refers to the installation location of the development tools.)

  3. Choose a template, such as Activity Monitor, to create the trace document.

    A trace document contains one or more instruments that collect data about a process.

  4. From the Default Target pop-up menu in the toolbar, select the iOS-based device containing the application from which you want to collect performance data.

  5. Add or remove instruments from the trace document to collect the desired data.

  6. Use the Default Target pop-up menu, to launch or attach to the target application.

  7. Click Record to start collecting data and use your application, exercising the areas you want to examine.

To learn more about measuring and analyzing application performance, see Instruments User Guide. This document provides general information about using Instruments.

The Shark Application

To complement the performance data Instruments collects, the Shark application lets you view system-level events, such as system calls, thread-scheduling decisions, interrupts, and virtual memory faults. You can see how your code’s threads interact with each other and how your application interacts with iOS.

When performance problems in your code are more related to the interaction between your code, iOS, and the hardware architecture of the device, you can use Shark to get information about those interactions and find performance bottlenecks.

For information about using Shark with your iOS applications, see Shark User Guide.




Last updated: 2010-07-02

Did this document help you? Yes It's good, but... Not helpful...