[swift-evolution] Bridging the gap between protocols and protocol extensions
rjmccall at apple.com
Sun Jan 10 19:34:32 CST 2016
> On Jan 10, 2016, at 5:21 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
>> If we make protocol extension methods dynamically dispatched (even as just an opt-in thing), we’d probably use a caching technique akin to objc_msgSend, keyed by the address of some global structure unique to the extension method. This has the huge advantage of not requiring eager resolution of every extension method on every conformance, and it can still be made very fast — on the order of a few dozen cycles, i.e. maybe 50-75% slower than a v-table dispatch. So it will not be as fast as a core requirement, but it’s likely to be close enough that all but the most performance-conscious programmers will be unaware of the difference, in the same way that most Java programmers have no need to be aware that dispatch through an interface type is usually slower than dispatch through a class type.
> Thanks, John. So if I'm reading this right:
> 1. It is a significant engineering effort (you can't just rearrange things in the existing vtables), but definitely doable.
> 2. It would have reasonably good performance, but performance-sensitive code might want a statically-dispatched alternative.
> Is that an accurate reading? Is it reasonable to propose for Swift 3, or would it require too much work for that timeframe?
It’s something we need to figure out before committing permanently to an ABI, and that makes it a logical part of the Swift 3 effort to at least leave room for this.
More information about the swift-evolution