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.
views:
262answers:
2You 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.
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.