views:

542

answers:

2

I a profiling my iPhone application on target, and according to Instruments 65% of the time is spent in mach_msg_trap.

I have a background thread that runs-forever and send results back to the main thread using performSelectorOnMainThread:withObject:waitUntilDone:, aproximately every 2 seconds. I am not waiting until done.

// Fredrik

A: 

If you're not expecting your main thread to be doing anything other than waiting on this background thread (or waiting for user input) there's nothing to be concerned about -- your application simply has nothing to do most of the time.

If you're expecting the main thread to be actively doing something else, please update your question to describe that. In this case, you might want to look at the full call stacks to mach_msg_trap as it's often at the bottom of a call stack where the actual time-waster is further up.

nall
I do not expect my main thread to do much except receive the update and redraw the screen once every 2 seconds. I do however expect my background thread to take every last clock cycle left over.
PeyloW
I still think it may be worth it to check out the callstack above mach_msg_trap just to double check your assumption about that the main thread should just be idling.
nall
+9  A: 
PeyloW
Source: http://developer.apple.com/mac/library/qa/qa2009/qa1619.html
Nickolay