Hacker Newsnew | past | comments | ask | show | jobs | submit | verstaen's commentslogin

You can use dlopen()/dlsym() to replicate something like objc_msgSend(). That's what I was doing for AppSketcher on BeOS.


I don’t quite follow how you’re using the functions in dlfcn to replace the Objective-C runtime?


There's a lot of caching involved. And it brings a lot of benefits.


There's no inline caching is there though? And so no 'mother of all optimisations' inlining. Or is my understanding of how Objective C works mistaken?

You wouldn't dream of implementing a dynamic language these days designed for performance without basic polymorphic inline caching. But Objective C seems to get by fine without it. Maybe it's not as essential as we think.


Do any statically compiled languages have inline caches? This would be a huge loss for ObjC, since it would greatly increase memory pressure by dirtying every text page.

ObjC has per-class out-of-line caches keyed by the selector (intern'd string).

It's true that there's no hope of inlining across a message send, but ObjC's C and C++ compatibility mitigates a lot of this expense. Apps routinely use C and C++ for perf critical sections.

Also some of Apple's APIs are inline C functions (NSMakeRect, etc) and others are designed to minimize dynamic dispatch. Iterating an NSArray typically requires only one message send (see the NSFastEnumeration protocol).

There's also more exotic techniques like IMP caching.


AFAIK objc_msgSend is always called, but it's very heavily optimized and written in assembly language. Mike Ash had a great post: https://www.mikeash.com/pyblog/friday-qa-2017-06-30-dissecti...


I wonder if /u/mikeash can still comment on this thread!

My recent experience has been that indeed inlining is essential for true "zero-cost abstraction"—say an array of integers with index set/get methods—but that once your abstraction is weighty enough that a method is performing more than a few dozen "interesting" instructions, inlining doesn't win much over how well the modern CPU can already optimize across calls.

EDIT: I should add I'm talking about static inlining. I'm sure your typical alien-technology JIT can identify the exact 800 instruction trace in your inner loop and pull it all together into a perfectly machine-sympathetic sequence that runs 50% faster than anything you could construct statically in the absence of profile-driven feedback.


There’s no inlining for Objective-C methods, if that’s what you’re alluding to, because the language dictates that every method call must be observable. objc_msgSend is generally really fast, though; it’s usually as fast as or faster than a virtual function call.


There’s no inlining, because determining whether inlining wpuld be safe is probably Turing-complete. However, IMP cacheing is a thing and that’s enough for most cases. For the rest there is C and (Objective-)C++.


Your comment was killed very quickly, strangely, but I though it had valid content so I revived it. The actual issue against inlining is that anybody can intercept method calls, even from places that the compiler cannot know about such as bundles loaded at runtime. So this isn’t even an issue with Turing-completeness; it’s an impossible problem to solve at compile time.


> at compile time

That's the key thing - other languages which solve this solve it dynamically.


Yeah, that’s what a JIT does. Unfortunately that’s not something that Apple really wants to open the door to on their platforms, especially for native code.


I don’t think that comes into play here. Objective-C is C, and although you could JIT any language, C isn’t made for it, both philosophically (one of its main claims to fame is ‘close to the metal’) and technically (a source file cold be compiled multiple times with different macro definitions or with a different set of #included files)


C isn't made for JIT because it's static; that's why inclining exists. Objective-C has room to improve because it has dynamic function calls.


C can also benefit from inline caching - function pointers!


Did you mean to say "NP-Complete" where you said "Turing-complete"?


A MacOS emulator was already available for BeOS and able to run any MacOS 9 application on BeOS. If I remember correctly the code name was "sheep shaver"...



Yep. It was amazingly smooth. I remember seeing Photoshop running, and crashing, without bringing the whole OS, which at the time was amazing.


Yep, but it would only run up to 8.x. I think, 8.5, but it could have been 8.1. They Mac OS after 8.5 changed a lot, and I think the BeOS version of sheepshaver stopped being able to load the OS.

It worked with no extra files on a Mac running BeOS, on a BeBox it required a dump of the toolbox ROM.


I ran Mac OS 8 in an emulator on my Amiga, just so I could access CompuServe email. MacOS actually ran faster on the Amiga hardware than on Apple's!


You still have the freedom to drink as much as you want in France. This is not about the freedom to drink, this is about fighting obesity.


That is not entirely true. For instance you can't drink in the street or be inebriated in public places.

France also used to serve wine in schools (http://img.over-blog-kiwi.com/1/47/74/06/20160130/ob_1c8cee_...).

Maybe some law makers will come up with the idea to forbid sugary drinks and fast food to less than 18 or 21 years old (like it is for alcohol and cigarettes in some countries).


> For instance you can't drink in the street

Untrue. A few municipalities forbid it, generally in specific places and/or for a specific duration, but the general rule is that it is allowed.

> or be inebriated in public places.

True, but not enforced. Only if you have done something wrong but they can't prove it or they don't want to bother proving it, they will (sometimes) charge you with that.


> > For instance you can't drink in the street

> Untrue. A few municipalities forbid it, generally in specific places and/or for a specific duration, but the general rule is that it is allowed.

My bad then: that's what I remembered from visiting France for some months at time.


Absolutely correct, it takes five years to be able to apply for citizenship for a green card holder. But a green card holder can move from job to job the way a US citizen does. So ince you have a green card, you are not submitted to the constraints of a visa.


Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: