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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With