Wednesday, September 24, 2014

Objective-C Drops vtable Optimization

Paul Stevenson:

In the last open-sourced objc runtime release, objc4-551, support for vtable dispatch was removed, and the clang options for supporting it have been mostly disabled.

Quinn “The Eskimo!”:

My understanding is that the optimisations that were done as part of the ARC effort eliminated the performance advantages derived from vtables.

Paul Stevenson:

You mean something like that retain/release/autorelease were three of the most important vtable selectors, and they’re mostly now not called via method dispatch since objc_retain()/objc_release()/etc short-circuit to the NSObject implementations for almost all objects?

I would guess that’s what Quinn meant, and this raises some questions:

  1. Does non-ARC code now see performance regressions, since the frequently used reference counting selectors are no longer optimized in this way?
  2. Why aren’t other common selectors worth the seemingly small cost of the vtable?
  3. If regular cached dispatch is fast enough that it isn’t worth using vtables, why is Apple discouraging message passing on performance grounds?

3 Comments RSS · Twitter

A few months ago I thought that with iOS 8 and Yosemite, non-ARC Objective-C would become deprecated the least. First signs of that happening next year?

@Maciej - I don't think they'll ever deprecate it. In fact, you sometime need it for low-level stuff, or interfacing with other languages. But I suspect there is less reason to optimize for it now.

Good point. Another more personal reason not to deprecate it - web services client Objective-C code awfully generated from WSDL that's impossible to ARCify. I had one project like that and feel dirty by just talking about it.

Leave a Comment