What percent of functions on OS X are called by the Objective-C runtime?

102 Views Asked by At

I'd like to get a firmer grasp of how frequently the runtime in any language that requires one is being called. In this case, I'm specifically interested in knowing:

Of all the function calls getting executed on an OS X or iOS system in any given second (approximations are of course necessary) how many of those are Objective-C runtime functions (i.e. functions that are defined by the runtime)?

2

There are 2 best solutions below

0
On

A lot. Here are just a few examples.

Every time you send a message, the actual message sending is done by a runtime function (this is in fact the most called runtime function in pretty much any objective C program).

NSObject class and protocol are not part of the standard library but part of the runtime, therefore any method that ends up executing to the default NSObject implementation is in fact executing runtime code.

Every time you execute a default property accessor (either read or write), that's part of the runtime.

If you use ARC, every time you access a weak reference (either for reading or writing it) that's a runtime function.

Objc runtime includes the C runtime, so anything that involves a C runtime function (for example passing a large structure by value or returning it) is in fact calling into the runtime.

and more.

0
On

Of course it depends on your application, but in general the answer is "a whole lot". Like, a whole freaking lot.

If you really want to see numbers, I'd recommend using dtrace to log all runtime functions as they're called. This blog entry talks about how to do such a thing.