Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: What is the processing overhead in invoking an Objective-C method?

I am writing some real-time audio processing code, which is to be executed in an audio unit's render callback.

This thread is at the highest priority level the system recognises.

Apple instructs to minimise the amount of processing that goes on in this call. One of their recommendations is to avoid Objective-C method invocation.

But why?

What happens when an Objective-C method is invoked? what is the actual overhead?

like image 908
P i Avatar asked Feb 25 '23 11:02

P i


1 Answers

Objective-C method resolution is dynamic. In other languages such as C or C++, a function call is set at compile time, essentially as a jump to the address that contains the function. In Objective-C however, method calls are implemented as 'sending messages' which don't work in the same way. There is a lookup process involved instead of a hardcoded jump.

This lookup process as an overhead associated with locating the address of the method to run. It is very optimised, but for certain types of code the overhead can cause performance issues.

Mike Ash gives a great writeup on what happens with Objective-C messaging if you're interested in additional detail.

like image 129
extremeboredom Avatar answered May 02 '23 20:05

extremeboredom