<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div>Oh, absolutely. It's just that the compiler is able to optimize through that under the right circumstances.</div><div><br class=""></div><div>When the generator is constructed, wrapped with anyGenerator() and used in the same module, the compiler can in theory inline everything and get rid of any boxes and dynamic dispatch, basically reducing it back to the actual generator.</div><div><br class=""></div><div>Basically, if the compiler can inline the AnyGenerator construction into the function where it's iterated over, this will work.</div><div>(But not if you construct the AnyGenerator with a closure. The compiler can't optimize that case (yet).)</div><div><br class=""></div><div>This might have been one of the reasons the AnyGenerator implementation was changed from Swift 1.2 > 2.0. IIRC it always used a closure for the type erasure before 2.0...</div><div><br class=""></div><div>Conceptually the same could also work for AnySequence I think. It's just that that is currently too complex for the optimizer to resolve even under ideal circumstances.</div><div><br class=""></div><div><br class=""></div><div>But this is more of a side-note about the current capabilities and limitations of the compiler. It's much simpler and more reliable to simply avoid AnyGenerator & AnySequence in most cases if their performance is an issue.</div><div><br class=""><blockquote type="cite" class=""><div class="">On 20 Dec 2015, at 18:11, Donnacha Oisín Kidney <<a href="mailto:oisin.kidney@gmail.com" class="">oisin.kidney@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I was under the impression that the biggest speed bump for AnyGenerator was that it was a class, rather than a struct? All of the generators on the standard library non-“Any” sequences are structs, for instance.<div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 20 Dec 2015, at 16:07, Janosch Hildebrand via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span class="Apple-tab-span" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: pre; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">        </span><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">* and can't use generic functions to solve your problem...</span><br class="Apple-interchange-newline"></div></blockquote></div><br class=""></div></div></div></blockquote></div><br class=""><div class="">
<div class="">- Janosch</div>
</div>
<br class=""></body></html>