|
> I have no idea what the right thing to do is in this situation, but having all those possibilities gives the compiler a better chance of producing faster code. When you introduce message passing, you basically forbid all of those optimizations, because now the function might be swizzled, go pass a "minX:Y:" string to objcMsgSend to find out what pointer we should jump to today. > Swift already does have a way to opt-in to message passing, it's called the @objc flag (and performSelector:). It works fine, but it's extra work to opt into it and use it. But, I don't think that's bad given that it disables so many useful optimizations. You could keep some of these optimizations if Swift's message-passing mechanism preserved type information. This would make it slower than objc_msgSend, but you could still keep a lot of cool optimizations. Some optimizations would still not be possible, and extensive use of function pointers does tend to frustrate branch prediction, but I feel that for most apps, this would be fast enough. > Finally, I fundamentally and strongly disagree with Michael about method swizzling and OSX extensibility. Adding PGP to Mail via hooking functions sounds like an incredibly deranged idea. The suggestion that programs should cooperate with a badly-misguided reverse engineering effort by disabling optimizations that make the program faster for the other 99% is just insane. The way to approach this is to build new kinds of extensions that provide known, safe, documented extension entrypoints for hooking arbitrary code. Yes that is more work, and yes it requires actually talking with people and convincing them of your point of view, but so do most things. I think this is a great argument, but unfortunately it's not where OS X is today. As I mentioned, app extensions may be a step towards a more workable solution, but today, the ability to add PGP to mail using method swizzling is important to thousands of Mail.app users. If 10.11 comes out and Mail.app has been rewritten in Swift before we have a good alternative to method swizzling, we'll have lost a lot of tools that make the Mac a powerful platform. |
Type information isn't what makes this fast. What makes it fast is the very guarantee that dynamic dispatch breaks: knowing, for a certainty, where the function will land.
> As I mentioned, app extensions may be a step towards a more workable solution, but today, the ability to add PGP to mail using method swizzling is important to thousands of Mail.app users.
A fast Mail app is important to millions of Mail users.
If PGP is important then one interim possibility is to write your own mail client. That requires extra work, but one of the hallmarks of important problems is that we are willing to do extra work to solve them.