Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can use to avoid the msgSend function overhead?(Obj-c)

Tags:

c

iphone

Hello everyone help me please!!!!

What can use to avoid the msgSend function overhead? maybe answer is IMP, but I not sure.

like image 569
ober Avatar asked Sep 13 '12 13:09

ober


1 Answers

You could simply inline the function to avoid any function call overhead. Then it would be faster than even a C function! But before you start down this path - are you certain this level of optimisation is warranted? You are more likely to get a better payoff by optimizing the algorithm.

The use of IMP is very rarely required. The method dispatching in Objective-C (especially in the 64-bit runtime) has been very heavily optimised, and exploits many tricks for speed.

What profiling have you done that tells you that method dispatching is the cause of your performance issue? I suggest first you examine the algorithm to see first of all where the most expensive operations are, and see if there is a more efficient way to implement it.

To answer your question, a quick search finds some directly relevant questions similar to yours right here on SO, with some great and detailed answers:

  • Objective-C optimization
  • Objective-C and use of SEL/IMP
like image 118
gavinb Avatar answered Oct 13 '22 00:10

gavinb