<div dir="ltr">why is runtime dispatch even necessary? Why can’t the client just call the specialized version directly?<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 5, 2017 at 2:01 AM, Slava Pestov <span dir="ltr"><<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space">Oh right. @_specialize modifies the original entry point to do runtime dispatch among the possible specializations. So the overhead comes from the unnecessary checks. I guess ideally we would have two versions of @_specialize, one adds the runtime dispatch whereas the other one just publishes static specializations which can be deserialized and used as needed.<div><br></div><div>Since @_specialize is not an officially supported attribute though, I would suggest punting this discussion until someone decides to push through an evolution proposal for it. For all intents and purposes, @inlinable is a superset of @_specialized because it defers the specialization decisions to the client.</div><span class="HOEnZb"><font color="#888888"><div><br></div></font></span><div><span class="HOEnZb"><font color="#888888">Slava</font></span><div><div class="h5"><br><div><br><blockquote type="cite"><div>On Oct 4, 2017, at 11:47 PM, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com" target="_blank">kelvin13ma@gmail.com</a>> wrote:</div><br class="m_-5652207453287779109Apple-interchange-newline"><div><div dir="ltr">See <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20170731/038571.html" target="_blank">the thread</a> from july over generic trig functions, where <span style="font-family:monospace,monospace">@_specialize()</span> + <span style="font-family:monospace,monospace">@_inlineable</span> had a small but consistent performance penalty relative to <span style="font-family:monospace,monospace">@_inlineable</span> alone.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 5, 2017 at 1:32 AM, Slava Pestov <span dir="ltr"><<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><div><div class="m_-5652207453287779109h5"><br><div><br><blockquote type="cite"><div>On Oct 4, 2017, at 11:04 PM, Taylor Swift <<a href="mailto:kelvin13ma@gmail.com" target="_blank">kelvin13ma@gmail.com</a>> wrote:</div><br class="m_-5652207453287779109m_-1619780893127709301Apple-interchange-newline"><div><div dir="auto"><div></div><div><br></div><div><br>On Oct 5, 2017, at 12:52 AM, Slava Pestov <<a href="mailto:spestov@apple.com" target="_blank">spestov@apple.com</a>> wrote:<br><br></div><blockquote type="cite"><div><br><div><br><blockquote type="cite"><div>On Oct 4, 2017, at 9:40 PM, Taylor Swift via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br class="m_-5652207453287779109m_-1619780893127709301Apple-interchange-newline"><div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">i’m just tryna follow along here && this is probably a dumb question, but is it possible for a generic function to be emitted as a set of specialized functions into the client, but not inlined everywhere? It can be the case where a large generic function gets slowed down by the large number of generic operations inside it but it doesn’t make sense for it to be inlined completely.</span></div></blockquote></div><br><div>This is already possible. The optimizer doesn’t have to inline an @_inlineable function at its call site; it can emit a call to a specialized version instead.</div><div><br></div><div>Slava</div></div></blockquote><br><div>Is there a reason using @_specialize() and @_inlineable together is slower than using @_inlineable by itself?</div></div></div></blockquote></div><br></div></div><div>By specialization, I mean the optimizer pass which takes a function body and substitutes generic parameters with statically-known types.</div><div><br></div><div>I’m not sure what your question means though. Adding a @_specialize attribute should never make anything slower. Rather it makes the optimizer eagerly emit specializations of a function in the defining module. You can think of @_specialize and @inlinable as mostly mutually exclusive; either you publish the complete function body for clients to optimize as they please, or you publish a fixed set of specializations.</div><div><br></div><div>You might prefer the latter for secrecy (serialized SIL is much closer to source code than machine code), but the the former enables more general optimizations.</div><span class="m_-5652207453287779109HOEnZb"><font color="#888888"><div><br></div><div>Slava</div></font></span></div></blockquote></div><br></div>
</div></blockquote></div><br></div></div></div></div></blockquote></div><br></div>