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

北城以北 提交于 2019-12-10 07:36:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/5700065/ios-what-is-the-processing-overhead-in-invoking-an-objective-c-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!