Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

< Previous PageNext Page > Hide TOC

High Performance

Performance is the perceived measure of how fast or efficient your software is, and it is critical to the success of all software. If your software seems slow, users may be less inclined to buy it. Even software that uses the most optimal algorithms may seem slow if it spends more time processing data than responding to the user.

Developers who have experience programming on other platforms (including Mac OS 9) should take the time to learn about the factors that influence performance on Mac OS X. Understanding these factors can help you make better choices in your design and implementation. For information about performance factors and links to performance-related documentation, see Performance Overview.

Table 7-1 lists several Mac OS X technologies that you can use to improve the performance of your software.

Table 7-1  Technologies for improving performance

Technology

Description

Universal Binaries

Because Macintosh computers may contain PowerPC or Intel processors, it is important to create universal binaries to ensure that your code always runs natively on the user’s computer. Native code runs much faster than emulated code and the Mach-O file format can easily accommodate multiple copies of your executable code in a single package. For information on how to create universal binaries, see Universal Binary Programming Guidelines, Second Edition.

64-bit

Although not appropriate in all cases, providing a 64-bit version of your application can improve performance, especially on Intel-based Macintosh computers. The 64-bit capable Intel processors typically have more hardware registers available for performing calculations and passing function parameters. More registers often leads to better performance. As always, test your code in both 32-bit and 64-bit modes to see if providing a 64-bit version is worthwhile. For more information, see 64-Bit Transition Guide.

NSOperation and NSOperationQueue

Mac OS X v10.5 includes two new Cocoa classes that simplify the process of supporting multiple threads in your application. The NSOperation object acts as a wrapper for encapsulated tasks while the NSOperationQueue object manages the execution of those tasks. Operations support dependency and priority ordering and can be customized to configure the threading environment as needed. For more information about these classes, see Threading Programming Guide.

Threads

With all new Macintosh computers shipping with multi-core processors, one way to take advantage of the extra computing power of these machines is to use threads to exploit any inherent parallelism in your software. Mac OS X implements user-level threads using the POSIX threading package but also supports several higher-level APIs for managing threads. For information about these APIs and threading support in general, see “Threading Support” and Threading Programming Guide.

Instruments and Shark

Apple provides a suite of performance tools for measuring many aspects of your software. Instruments and Shark in particular provide new ways of looking at your application while it runs and analyzing its performance. Use these tools to identify hot spots and gather performance metrics that can help identify potential problems. For more information Instruments, see “Instruments.” For information about Shark and the other performance tools that come with Mac OS X, see “Performance Tools.”

Accelerate Framework

The Accelerate framework provides an API for performing multiple scalar or floating-point operations in parallel by taking advantage of the underlying processor’s vector unit. Because it is tuned for both PowerPC and Intel processor architectures, using the Accelerate framework eliminates the need for you to write custom code for both the AltiVec and SSE vector units. For more information about using this framework, see Accelerate Release Notes.

Lower-level APIs

Mac OS X provides many layers of APIs. As you consider the design of your application, examine the available APIs to find the appropriate tradeoff between performance, simplicity, and flexibility that you need. Usually, lower-level system APIs offer the best performance but are more complicated to use. Conversely, higher-level APIs may be simpler to use but be less flexible. Whenever possible, choose the lowest-level API that you feel comfortable using.

Mac OS X supports many modern and legacy APIs. Most of the legacy APIs derive from the assorted managers that were part of the original Macintosh Toolbox and are now a part of Carbon. While many of these APIs still work in Mac OS X, they are not as efficient as APIs created specifically for Mac OS X. In fact, many APIs that provided the best performance in Mac OS 9 now provide the worst performance in Mac OS X because of fundamental differences in the two architectures.

Note: For specific information about legacy Carbon managers and the recommended replacements for them, see “Carbon Considerations.”

As Mac OS X evolves, the list of APIs and technologies it encompasses may change to meet the needs of developers. As part of this evolution, less efficient interfaces may be deprecated in favor of newer ones. Apple makes these changes only when deemed absolutely necessary and uses the availability macros (defined in /usr/include/AvailabilityMacros.h) to identify deprecated interfaces. When you compile your code, deprecated interfaces also trigger the generation of compiler warnings. Use these warnings to find deprecated interfaces, and then check the corresponding reference documentation or header files to see if there are recommended replacements.



< Previous PageNext Page > Hide TOC


Last updated: 2007-10-31




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice