Method dispatch in Swift
raizlabs.com
raizlabs.com
Java uses table dispatch by default, but you can opt into
direct dispatch by using the final keyword. C++ uses direct
dispatch by default, but you can opt into table dispatch by
adding the virtual keyword. Objective-C always uses message
dispatch, but allows developers to fall back to C in order
to get the performance gains of direct dispatch. Swift has
taken on the noble goal of supporting all three types of
dispatch.
I kinda already knew this but it's nice and succinct.This is not accurate. Java does not use table dispatch by default. The HotSpot compiler will optimize most code to use direct dispatch, reserving table dispatch only for cases where calls cannot be inlined; and final does not particularly enable direct dispatch.
A discussion of these issues: http://www.ibm.com/developerworks/java/library/j-jtp1029/ind...
> Like many myths about Java performance, the erroneous belief that declaring classes or methods as final results in better performance is widely held but rarely examined. The argument goes that declaring a method or class as final means that the compiler can inline method calls more aggressively, because it knows that at run time this is definitely the version of the method that's going to be called. But this is simply not true. Just because class X is compiled against final class Y doesn't mean that the same version of class Y will be loaded at run time. So the compiler cannot inline such cross-class method calls safely, final or not. Only if a method is private can the compiler inline it freely, and in that case, the final keyword would be redundant.
> On the other hand, the run-time environment and JIT compiler have more information about what classes are actually loaded, and can make much better optimization decisions than the compiler can. If the run-time environment knows that no classes are loaded that extend Y, then it can safely inline calls to methods of Y, regardless of whether Y is final (as long as it can invalidate such JIT-compiled code if a subclass of Y is later loaded). So the reality is that while final might be a useful hint to a dumb run-time optimizer that doesn't perform any global dependency analysis, its use doesn't actually enable very many compile-time optimizations, and is not needed by a smart JIT to perform run-time optimizations.
Yes, was about to point this out, one of the more resilient misconceptions about Java. I've lost count of how many times I had to explain this and remove a boatload of unnecessary "final".
Most Java JIT compilers will also opt you into direct dispatch automatically where possible, for example a class with no subclasses or an interface with only one implementation.
They'll also opt you into direct dispatch per call site if a given call site has only ever seen objects of a single class.
This is an example of how it possible for a JIT to out-perform a static compiler.
This is what is called PGO, profile guided optimization.
Basically you do several test runs using real use cases, under a profiler and then do a release build using the PGO gathered data as additional input.
If it had these, most abuses of monospace preformatted text would disappear.
It uses static dispatch by default, virtual dispatch like C++ and Object Pascal, dynamic dispatch like Objective-C.
[1] https://blogs.msdn.microsoft.com/ericgu/2008/07/02/why-does-...
[2] §6.1 of the C# language spec.
https://www.microsoft.com/resources/msdn/en-us/msdntv/200511...
For dynamic invocations, Objective-C style, you can see here:
https://msdn.microsoft.com/en-us/library/dd264741.aspx
https://msdn.microsoft.com/en-us/library/ee461504.aspx#Ancho...
Great read, good to know this stuff. I encountered a few of these examples while poking around with more complex features in the language.
All the recent Objective-C features were added to improve the compatibility between both languages, reducing Objective-Cisms in Swift.
`Optional`s being baked into the language, using `Result` types, `guards`, `if let`, pattern matching, great support for Rx, and lots of other fun and cool stuff, easy use of high-level features with possibility to dive deeper, while still being able to use all the features of Cocoa, Cocoa Touch, and all the other frameworks and features of macOS, iOS, watchOS, and appletvOS as a native citizen, and also write code that runs better everyday on Linux, is a really great package. Swift Package Manager is also great and becomes better everyday.
Swift is a good combination of a great language that supports a lot of cool platforms and has a lot of tools available.
If that's the case it's kind of a weird way to put it, though it sort of squares with the witnesses in proof-relevant formulations of logout where you care about the form of a proof and not just what it proves.
"a witness is a specific value t to be substituted for variable x of an existential statement of the form ∃x φ(x) such that φ(t) is true"
In the less abstract: a witness is someone who, because he has looked at data, can tell you something about that data.
A witness table contains the statements of multiple witnesses. In this case, the statements are of the form "'A' is a value for which the statement 'you can find the code implementing method M for class C at address x' is true".
As the article states "Most languages refer to this as a “virtual table". I find the use of Witness table strange here. I know it from string matching algorithms, where the witness statements are of forms such as "if you start comparing here, the fourth character is the first that doesn't match".
The AUR packages are broken without downgrading llvm which I can't do atm, and there are no prebuilt generic linux versions... -.-
The other problem is that the mess basically starts there, e.g. Swift programs in practice also depend on Glibc and so after you kill the first turtle it's still turtles all the way down.
You could build an Arch with Glibc, but why you would want to is not immediately clear.
Arch is glibc-based. What are you on about?