views:

262

answers:

2

I was wondering what people is doing in order to compile their iPhone applications optimizing them for maximum speed rather than size or the tradeoff speed versus size.

+5  A: 

You should always, always profile your code before making any blanket assumptions about what is good or bad for your particular app. Shark is really nice and is able to use the hardware performance counters on your device to tell you lots of low-level details about how your application is running.

On iPhone 3GS, compiling for Thumb-2 doesn't incur the performance penalty that the older Thumb instruction set does (it has native floating point, in particular). See this other question for some additional details.

You can produce binaries with more than one instruction set in them, though I'm not sure if you can say "no thumb" for ARM6 (pre-iPhone 3GS) and "thumb OK" for ARM7 (iPhone 3GS, presumably iPad, don't know about iPod touches). Edit: This is possible, thanks Brad for explaining how.

In many cases, optimizing for size is also a good way to optimize for speed: by squeezing your code size, it may fit better into the CPU's instruction cache, avoiding fetches to memory. This helps more often with frequently executed tight loops.

Steve Madsen
+1 for the profiling advice. Even modest changes in the algorithms will often give you orders of magnitude more performance than fiddling with compiler settings.
zoul
You can make building for Thumb conditional by selecting the Compile for Thumb option, and going to the menu at the lower left of the build screen and selecting Add Build Setting Condition. In the new condition, select ARMv6 for one condition, turn off Thumb, and add a new condition for ARMv7 with Thumb left on.
Brad Larson
A: 

No. 1 tip - know your storage classes. Doing something like indexOfObject on an array can be incredibly expensive and you can usually avoid those situations by using a different storage class or organising your data differently. The performance tools can help you find these situations.

Adam Eberbach