<div dir="ltr">Functions in a module go through dynamic dispatch. Operators are functions. So multiplying two complex numbers won&#39;t get inlined. The stdlib uses internal tricks so what appears as a module you import is available to be specialized and inlined.<div><br></div><div>To see this in action, try the CubeWorld demo from here: <a href="https://github.com/AE9RB/SwiftGL" target="_blank" style="font-size:13px">https://github.com/AE9RB/SwiftGL</a></div><div>Then change it so the math libraries aren&#39;t modules (move the files, delete the import statements). On my system, CPU drops from 60% to 6%. It&#39;s also the difference between 150 cubes and 1200 cubes at 60 fps. Make sure you turn on WMO.</div><div><br></div><div>I&#39;m told it won&#39;t always be this way. But it is today.</div><div><br></div><div>-david </div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 6:18 PM, Trent Nadeau <span dir="ltr">&lt;<a href="mailto:tanadeau@gmail.com" target="_blank">tanadeau@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I&#39;m confused. Why would you get dynamic dispatch for a complex number just because it&#39;s in another module? I think a complex number would always be a struct so everything would be inline to the storage on the stack, and there&#39;s no inheritance so no vtable.</div><div class="gmail_extra"><div><div class="h5"><br><div class="gmail_quote">On Tue, Jan 26, 2016 at 7:46 PM, David Turnbull via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Rust has a Nursery. C++ gets a Boost. Swift is a Breeze? The only problem is that a lot of stdlib-like things aren&#39;t suitable for modules.<div><div><br></div><div>For example, it would be unfortunate if a blogger was comparing languages and benchmarked FFT using complex numbers from a module in the breeze. Dynamic dispatch is going to devastate the benchmarks.</div><div><br></div><div>Still, it&#39;s worth pursuing this. There&#39;s a lot of things which Apple supports on Apples and won&#39;t be a priority for stdlib. The quaternions you mentioned are a good example. Complex numbers are another because of Accelerate.</div><div><br></div><div>-david  <a href="https://github.com/AE9RB/SwiftGL" target="_blank">https://github.com/AE9RB/SwiftGL</a></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div>On Tue, Jan 26, 2016 at 3:32 PM, Tino Heth via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div dir="auto"><div><span></span></div><div><div><span></span></div><div>There have been several threads to add specific functions or types to the stdlib:<div>- <span style="font-family:&#39;Helvetica Neue&#39;">Either in the Swift Standard Library</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- </span><span style="font-family:&#39;Helvetica Neue&#39;">Proposal: Add scan, takeWhile, dropWhile, and iterate to the stdlib</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- Higher Kinded Types (Monads, Functors, etc.)</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- </span><span style="color:rgb(76,76,76);font-family:&#39;Helvetica Neue&#39;">Adding a new filter method which returns 2 arrays</span></div><div><span style="color:rgb(76,76,76);font-family:&#39;Helvetica Neue&#39;">- </span><span style="font-family:&#39;Helvetica Neue&#39;">Add replace(_:with:) function to the stdlib</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- map-like operation that returns a dictionary</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- </span><span style="font-family:&#39;Helvetica Neue&#39;">Rectangles and other common structures.</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- </span><span style="font-family:&#39;Helvetica Neue&#39;">Add zip2WithNilPadding function</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">- </span><span style="font-family:&#39;Helvetica Neue&#39;">Add types BufferedSequence, BufferedGenerator</span></div><div><font face="Helvetica Neue">- … (guess there are some that I missed — I didn&#39;t look at last years threads at all).</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="Helvetica Neue">Afair, none of those ideas turned into real proposals, and I think that keeping stdlib small is a good goal.</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="Helvetica Neue">Nonetheless, there are plenty of data structures and algorithms that will be used in many places by many different teams, and each of them might write its own implementation. That&#39;s imho no big problem for algorithms, but for types, it will most likely lead to real annoyance.</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="Helvetica Neue">I hope that we will soon have a great package manager for Swift, but I don&#39;t think that will solve this issue completely:</font></div></div><div><font face="Helvetica Neue">I wouldn&#39;t import a big third-party framework just because a tiny function like &quot;dropWhile&quot; could make my code more elegant...</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="Helvetica Neue">Of course, some widely accepted libs might rise and improve interoperability, but it is hard to predict how our ecosystem will evolve, and you don&#39;t have to wait for the future to see the what could happen when there is no common base</font><font face="Helvetica Neue">:</font></div><div><span style="font-family:&#39;Helvetica Neue&#39;">Just take a look at SCNQuaternion, GLQuaternion and CMQuaternion.</span></div><div><br></div><div><span style="font-family:&#39;Helvetica Neue&#39;">Instead of asking to pollute stdlib with stuff like 3d transformations, I&#39;d prefer a set of general purpose libraries under supervision by the Swift team:</span></div><div><span style="font-family:&#39;Helvetica Neue&#39;">It could be a great way for &quot;outsiders&quot; to get into Swift development, and most likely wouldn&#39;t put to much stress and responsibility on the shoulders of each &quot;manager&quot;.</span></div><div><font face="Helvetica Neue">It also could take pressure from the stdlib (and this mailinglist :)</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="Helvetica Neue">Beside fields of application (graphics, images, music, algebra, statistics, pattern matching, machine learning, graph theorie... whatever raises enough interest), there could also be libraries to support concepts like functional programming.</font></div><div><font face="Helvetica Neue"><br></font></div><div><font face="Helvetica Neue">Best regards,</font></div><div><font face="Helvetica Neue">Tino</font></div></div><div><br></div></div><br></div></div><span>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></span></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div>Trent Nadeau</div>
</font></span></div>
</blockquote></div><br></div>