<story><title>Method dispatch in Swift</title><url>https://www.raizlabs.com/dev/2016/12/swift-method-dispatch/</url></story><parent_chain><item><author>CalChris</author><text>&lt;p&gt;&lt;pre&gt;&lt;code&gt;  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.
&lt;/code&gt;&lt;/pre&gt;
I kinda already knew this but it&amp;#x27;s nice and succinct.</text></item></parent_chain><comment><author>jcrites</author><text>&amp;gt; Most languages support one or two of these. Java uses table dispatch by default, but you can opt into direct dispatch by using the final keyword.&lt;p&gt;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.&lt;p&gt;A discussion of these issues: &lt;a href=&quot;http:&amp;#x2F;&amp;#x2F;www.ibm.com&amp;#x2F;developerworks&amp;#x2F;java&amp;#x2F;library&amp;#x2F;j-jtp1029&amp;#x2F;index.html&quot; rel=&quot;nofollow&quot;&gt;http:&amp;#x2F;&amp;#x2F;www.ibm.com&amp;#x2F;developerworks&amp;#x2F;java&amp;#x2F;library&amp;#x2F;j-jtp1029&amp;#x2F;ind...&lt;/a&gt;&lt;p&gt;&amp;gt; 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&amp;#x27;s going to be called. But this is simply not true. Just because class X is compiled against final class Y doesn&amp;#x27;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.&lt;p&gt;&amp;gt; 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&amp;#x27;t perform any global dependency analysis, its use doesn&amp;#x27;t actually enable very many compile-time optimizations, and is not needed by a smart JIT to perform run-time optimizations.</text></comment>
<story><title>Method dispatch in Swift</title><url>https://www.raizlabs.com/dev/2016/12/swift-method-dispatch/</url></story><parent_chain><item><author>CalChris</author><text>&lt;p&gt;&lt;pre&gt;&lt;code&gt;  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.
&lt;/code&gt;&lt;/pre&gt;
I kinda already knew this but it&amp;#x27;s nice and succinct.</text></item></parent_chain><comment><author>schrodinger</author><text>It&amp;#x27;s so hard to read those horizontally-scrolling fixed-width text blurbs on mobile!!!</text></comment>