3 ms·
I think the biggest issue is that in a vtable you jump directly to the method by index, and with objc_msgsend it looks up a string in a hash table. Mostly the
by fleitz 11y ago
I think the biggest issue is that in a vtable you jump directly to the method by index, and with objc_msgsend it looks up a string in a hash table.
Mostly the difference is ints vs. strings in my opinion.
As well in C++ if you don't mark your method virtual you can bypass all the vtable crap.
I love ObjC but method resolution is far more expensive than in C++, especially non-virtual methods.
- astrange 11y agoMethod selectors in Obj-C don't have to be strings, as long as you can turn a string into one occasionally. You do still need to do a hash lookup to get the method implementation, since the selector table changes at runtime and objects have to safely respond to unhandled selectors and all that.
- fleitz 11y agoI meant string as in char* not NSString, selectors specifically the SEL datatype are strings They certainly don't have to be, however, they are. SEL selector = @selector(applicationDidBecomeActive:); printf("%s",(char*)(void*)selector); // Prints applicationDidBecomeActive: