5 ms·
Objective-C uses a hash table cache for all method calls. It's a bit different in that Objective-C deals with collisions by just not handling them: since it's o
by pcwalton 7y ago
Objective-C uses a hash table cache for all method calls. It's a bit different in that Objective-C deals with collisions by just not handling them: since it's only a cache, collisions will result in going through the slow name lookup path.
Mike Ash has a nice series that goes through the disassembly of objc_msgSend: https://www.mikeash.com/pyblog/friday-qa-2017-06-30-dissecting-objc_msgsend-on-arm64.html https://www.mikeash.com/pyblog/friday-qa-2017-06-30-dissecti...
- perishabledave 7y agoMike Ash’s posts are gold. I wish there were more in depth technical posts like those on HN or Lobsters.
- saagarjha 7y ago> Objective-C uses a hash table cache for all method calls. Nit: method calls to objects that are not nil, since the latter causes objc_msgSend to bail out before the hash table is consulted.
- jonathanstrange 7y agoBut aren't hash tables orders of magnitude slower than dynamic dispatch with jump tables? I'm just interested in PL implementation as a hobby, so correct me if I'm wrong, but this seems horribly inefficient to me.
- tcard 7y agoYou can't use jump tables in Objective-C because methods can be added to objects at runtime.
- masklinn 7y agoThat doesn't preclude using jump tables. You can also add methods to objects at runtime in JS and modern runtimes use jump tables. I expect you can't use jump tables in objc because you can't really "patch in" jump tables at runtime as it's AOT-compiled rather than JIT-ed.
- tcard 7y agoRight, but that's no longer "just" jump tables, you need additional JIT logic for those tables to be correct. Plus, in a JIT you can go even further and just do direct calls, no need for the indirection of tables.
- jcelerier 7y agowell, does macOS feel like a fast operating system to you ?