Re:Dissecting objc_msgSend on ARM64
by nimrody on Saturday July 01, 2017 @12:00PM
(#14677628)
Even the method cache seems expensive -- compared to an indirect function call (using a virtual method table). Can clang replace msgSend with direct calls when the destination class is known at compilation time? (perhaps with a guard to verify that the object class is as expected)
[ Parent
| on HN ]
Re:Dissecting objc_msgSend on ARM64
by thought_alarm on Saturday July 01, 2017 @02:04PM
(#14678146)
You have that option in performance-critical situations. The ObjC runtime does allow you to lookup a method's underlying function pointer ahead of time in order to bypass obj_msgSend.
The compiler can't do that automatically because the any method and any class can be replaced at any time. Key-value observing is a common feature that replaces method implementations on the fly at runtime.
Re:Dissecting objc_msgSend on ARM64
by plorkyeran on Saturday July 01, 2017 @02:09PM
(#14678170)
KVO creates a new subclass and changes your object to that subclass rather than replacing methods on the original class, so checking the isa pointer would be sufficient for that case. Method swizzling would break, but I suspect that most obj-c code could be compiled without support for swizzling without breaking anything.
Re:Dissecting objc_msgSend on ARM64
by icodestuff on Saturday July 01, 2017 @04:07PM
(#14678721)
Swizzling is not the only thing that would break. You'd break categories in dynamically loaded frameworks or bundles, and yes, you'd still break KVO because it replaces -dealloc and -class on the newly-created classes.
You'd also break dynamically adding methods to classes.
Re:Dissecting objc_msgSend on ARM64
by CodeWriter23 on Saturday July 01, 2017 @06:57PM
(#14679546)
What is a typical use case for dynamically adding methods to a class?
No, this never happens. (Method implementations can be replaced at runtime.)
Re:Dissecting objc_msgSend on ARM64
by chrisseaton on Saturday July 01, 2017 @02:13PM
(#14678193)
No - and this is the advantage of JIT compilers which can do that and why they can sometimes outperform static compilers.