News for hackers. Stuff that matters.
Re:Brad Cox has died by userbinator on Friday January 22, 2021 @10:48PM (#25879433)
Coincidentally, I've been doing RE for many years, starting in the days of DOS and then moving into Windows, but it was only very recently --- less than a week ago --- that I had my first look at an app written in ObjC, and the first thing I noticed was the amount of information in the binary that seemed to almost give away most of its source: method, field, and class names everywhere. When I saw a method named something like checkLicenseSignature, I almost thought it was misdirection.

The second thing that I found astonishing was that these strings were actually being used by the runtime to determine what to call, i.e. something that in basically every other native language I've seen would be a direct or indirect call to an address or vtable offset. All this in an application that has no exported functions. I can definitely see how it would make RE extremely straightforward! Efficiency, on the other hand...

Re:Brad Cox has died by sorbits on Saturday January 23, 2021 @04:35AM (#25880955)
> All this in an application that has no exported functions

This is not strictly true: On macOS/iOS the OS/frameworks/plug-ins may call your methods, likewise with support for services, input managers, distributed objects, etc.

The responder chain is a good example of this dynamism: The input manager (responsible for interpreting key strokes) translate the user’s input into a message, e.g. “copy” or “insert A” and then finds the first object in the chain of objects that responds to this message.

This chain of objects may consist of standard framework objects (like a text view) or it may be your custom objects (like a view controller subclass).

In most other environments, you would have to create special interfaces for stuff you want to make public, this means only that stuff suffers the performance overhead, but you generally pay the cost in code complexity, see e.g. Window’s Component Object Model.

Re:Brad Cox has died by DaiPlusPlus on Saturday January 23, 2021 @01:49AM (#25880250)
> these strings were actually being used by the runtime to determine what to call

Fortunately it doesn't do a full string comparison - it just compares the value of the string pointers, I understand.

Re:Brad Cox has died by saagarjha on Saturday January 23, 2021 @03:48AM (#25880737)
Yes: selectors are interned.
Re:Brad Cox has died by saagarjha on Friday January 22, 2021 @11:12PM (#25879568)
Objective-C, at least these days, is plenty fast, with a the cost of a message send being comparable to a virtual function call. The fast path of objc_msgSend is just over a dozen instructions.
Re:Brad Cox has died by nielsbot on Saturday January 23, 2021 @12:24AM (#25879910)
Plus for critical sections you can obtain method pointers which are just C functions.
Re:Brad Cox has died by bitexploder on Saturday January 23, 2021 @05:46AM (#25881323)
The M1 chip has specialized paths on it just to make the message sending even faster. That’s part of the M1 magic.
Re:Brad Cox has died by saagarjha on Saturday January 23, 2021 @06:59AM (#25881626)
To be fair I think the extent of this specialization is a branch hint
Re:Brad Cox has died by bitexploder on Saturday January 23, 2021 @07:45PM (#25887643)
It’s still a kind of neat trick. One of those paths where even a little optimization goes a long way due to it being so hot.
Re:Brad Cox has died by why_only_15 on Saturday January 23, 2021 @01:26AM (#25880155)
as i recall, `libobjc` is ~25% of app launch time. `objc_msgSend` is quite expensive when you're making hundreds of thousands to millions of calls per second.
Re:Brad Cox has died by pjmlp on Saturday January 23, 2021 @02:38AM (#25880453)
Although Swift has the spotlight, Objective-C keeps being improved.

"Advancements in the Objective-C runtime"

https://developer.apple.com/videos/play/wwdc2020/10163/

Re:Brad Cox has died by jcfields on Saturday January 23, 2021 @10:11AM (#25882747)
Swift uses the Objective-C runtime.
Re:Brad Cox has died by pjmlp on Saturday January 23, 2021 @11:46AM (#25883723)
Swift can uses the Objective-C runtime for interoperability with Objective-C code, just like .NET uses COM on Windows.

They need to interoperate with the rest of the platform.

Re:Brad Cox has died by microtherion on Saturday January 23, 2021 @10:42AM (#25882994)
Swift is tiptoeing between static and dynamic typing, preferring the former when feasible, but often needing some of the latter when dealing with the UI.
Re:Brad Cox has died by saagarjha on Saturday January 23, 2021 @05:33AM (#25881261)
I would guess that most of app startup time isn't going to objc_msgSend (although it is still probably slow as it hasn't warmed up yet) but rather to setting up the various data structures used by the runtime, applying initial swizzling and the associated cache invalidation that comes from that, and those pesky +loads that every analytics framework thinks it need to have ;)
Re:Brad Cox has died by AJRF on Saturday January 23, 2021 @04:45AM (#25881016)
The compiler does some very fancy stuff with objc_msgSend to make it fast, and the selectors are interned.

https://www.mikeash.com/pyblog/objc_msgsends-new-prototype.h...

Re:Brad Cox has died by donarb on Saturday January 23, 2021 @02:10PM (#25885168)
Objective-C had an IMP pointer, essentially a function pointer. If you needed to send a message to an object in a tight loop, you could extract the pointer before the loop and use it inside.