Earlier quoted context omitted.
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.
Can you recreate Objective-C in C?
11–20 of 41 posts
Re: Can you recreate Objective-C in C?
#12> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…
Re: Can you recreate Objective-C in C?
#13> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…
Can you link to any info about implementation details for objc? I’ve been trying to make my own language and this seems helpful.
Re: Can you recreate Objective-C in C?
#14Earlier quoted context omitted.
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.
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++.
Re: Can you recreate Objective-C in C?
#15Earlier quoted context omitted.
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.
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.
Re: Can you recreate Objective-C in C?
#16> Objective-C under the hood compiles every method call into a call to the function objc_msgSend(). Well, kinda. You need a family of functions (objc_msgSend, of course, but also objc_msgSend_stret, objc_msgSendSuper, and objc_msgSendSuper_stret), to get this to really work for when you have structures as your return value or are calling a superclass's implementation (or both!). Since the inline assembly that is objc…
Can you link to any info about implementation details for objc? I’ve been trying to make my own language and this seems helpful.
It has posts where he recreates the functionality of the runtime, but without the optimizations that are in Apples runtime (which is open source).
Re: Can you recreate Objective-C in C?
#17Major misunderstanding about turing completeness.
A language is so much richer than simply enabling you to write a map from inputs to outputs. Sure you could probably rewrite my Haskell program in Fortran in the sense that the Fortran program produces the exact same outputs for any given inputs...but it's hardly convincing to me that you "recreated" my program in Fortran after dropping my monad transformers and lenses.
Regardless, you wouldn't even be able to generally prove (assuming you lack dependent typing) that your program is functionally equivalent to mine (since this is undecidable).
Re: Can you recreate Objective-C in C?
#18You can use dlopen()/dlsym() to replicate something like objc_msgSend(). That's what I was doing for AppSketcher on BeOS.
Re: Can you recreate Objective-C in C?
#19Earlier quoted context omitted.
Can you link to any info about implementation details for objc? I’ve been trying to make my own language and this seems helpful.
Check out Mike Ashes blog: https://mikeash.com/pyblog/ It has posts where he recreates the functionality of the runtime, but without the optimizations that are in Apples runtime (which is open source).
Also bbum, he does a lot of posts on SO about this stuff, and I thought he wrote blog posts on the subject too but can't seem to find them.
Re: Can you recreate Objective-C in C?
#20Earlier quoted context omitted.
Check out Mike Ashes blog: https://mikeash.com/pyblog/ It has posts where he recreates the functionality of the runtime, but without the optimizations that are in Apples runtime (which is open source).
Can confirm that mikeash knows a lot about this stuff and posted a lot about it. Also bbum, he does a lot of posts on SO about this stuff, and I thought he wrote blog posts on the subject too but can't seem to find them.
Well, he works on Apple’s runtime team now, so it would be bad if he didn’t ;)