[swift-evolution] Bridging the gap between protocols and protocol extensions

Brent Royal-Gordon brent at architechies.com
Sun Jan 10 19:21:09 CST 2016


> 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?

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list