Reputation: 31
I have an iOS application that grabs frames from the devices camera and does some quite CPU intensive image processing. On the iPad 2, iPad 3 and iPhone 4s the application happily runs at 30 frames per second (fps). I recently tested it on an iPhone 5 and most of the time it runs at 30 fps. Occasionally i've noticed it drop to around 15 fps, something I've never experienced on the other devices (devices that supposedly have slower hardware). I've tried hard to track this issue down, and I've learn a bunch of stuff but not found an explanation. Here are some of my observations that might give clues to what is going on:
This is very odd. Could it be that the iPhone 5 reduces the clock speed of the phone sometimes to help with battery life (in a way that iPads and the iPhone 4s doesn't)?
I'd love to hear from anyone who as had similar experiences.
My application shouldn't look worse on iPhone 5 it should look better!
Many thanks in advance,
Kevin
Update
I've done some more tests but have still not found the problem. This is what I tried.
I've run out of ideas. Love to hear from any one who has experience frame rate slowdowns on the iPhone 5? Does the iPhone 5 have a power save mode?
Upvotes: 2
Views: 1556
Reputation: 299623
The most likely cause is a race condition in your code that only gets tripped by the particular timings on iPhone 5. I'd look around for anywhere you have resource contention and make sure that you're handling them correctly, and especially anywhere that you perform timeouts (since you don't fully deadlock or crash).
You mention that you're running on multiple threads. Do you mean that you're using NSThread
, performSelectorInBackground:
, NSOperation
, or GCD? Using NSThread
directly is a common cause of threading and resource problems because it's harder to do things correctly with it than with NSOperation
or GCD.
If you ever call performSelectorInBackground:
, I would highly suspect that piece of code since this call is extremely easy to use incorrectly (and should pretty much never be used). The fact that leaving the app and re-launching it tends to cause the problem would especially make me suspect that you're spawning threads manually in view controllers (which is a common mistake). The problem with performSelectorInBackground:
is that there's no easy way to know that you've already spawned a thread for this. So you can wind up with many more threads than you meant to.
As in all performance things, you should start with Instruments. Look particularly at the time profiler and the threading instruments.
One more somewhat common cause of this kind of problem: audit your use of NSLog
. It is extremely slow and synchronous. Running it on multiple threads can significantly impact performance.
Upvotes: 2