<div dir="ltr">Hm. I'm not sure if the performance difference is a hard limitation because of implementation decisions, or if it would be possible to make the current implementation as fast as the closure-based implementation. I don't understand enough about the codegen (and about possible optimizations) to make that decision. Anyone who's willing to help me there?</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Sep 15, 2016 at 5:01 PM, Dave Abrahams via swift-dev <span dir="ltr"><<a href="mailto:swift-dev@swift.org" target="_blank">swift-dev@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
on Tue Sep 06 2016, Chris Eidhof <swift-dev-AT-swift.org> wrote:<br>
<br>
> Thanks! That explains a lot.<br>
><br>
> In my version, performance only is improved by 10%, so I'm not sure if the<br>
> tradeoff is worth it:<br>
><br>
> In the isolated case of AnyIterator, there's only one method, so the sizeof<br>
> is the same (and the performance is worth it). In the case of AnySequence,<br>
> it would be a lot more work to write the implementation (and the size would<br>
> change a lot). Having two different mechanisms for type erasure seems like<br>
> it might confuse things even more.<br>
<br>
</span>We'll happily take a litte more implementation complexity in exchange<br>
for performance gains. 10% is nothing to sneeze at.<br>
<div><div class="h5"><br>
> On Mon, Sep 5, 2016 at 9:50 PM, Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>> wrote:<br>
><br>
>> On Mon, Sep 5, 2016 at 11:13 AM, Chris Eidhof via swift-dev<br>
>> <<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a>> wrote:<br>
>> > Hello swift-dev,<br>
>> ><br>
>> > I was wondering why type erasers (e.g. for AnyIterator) are implemented<br>
>> the<br>
>> > way they are. I would implement AnyIterator like this:<br>
>> ><br>
>> > final class MyAnyIterator<A>: IteratorProtocol {<br>
>> > var nextImpl: () -> A?<br>
>> ><br>
>> > init<I: IteratorProtocol>(iterator: I) where I.Element == A {<br>
>> > var copy = iterator<br>
>> > nextImpl = { copy.next() }<br>
>> > }<br>
>> ><br>
>> > func next() -> A? {<br>
>> > return nextImpl()<br>
>> > }<br>
>> > }<br>
>> ><br>
>> > Instead, it is implemented in a class which contains a box.<br>
>><br>
>> Your approach requires adding a new closure property for every method<br>
>> that is forwarded. Subclassing does not require that.<br>
>><br>
>> If you see a case where performance is not good, we would appreciate a<br>
>> bugreport at <a href="https://bugs.swift.org/" rel="noreferrer" target="_blank">https://bugs.swift.org/</a> . Please attach a self-contained<br>
>> reproducer. Thank you.<br>
>><br>
>> Dmitri<br>
>><br>
>> --<br>
>> main(i,j){for(i=2;;i++){for(j=<wbr>2;j<i;j++){if(!(i%j)){j=0;<wbr>break;}}if<br>
>> (j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
>><br>
<br>
--<br>
</div></div>-Dave<br>
<br>
______________________________<wbr>_________________<br>
swift-dev mailing list<br>
<a href="mailto:swift-dev@swift.org">swift-dev@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-dev" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-dev</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Chris Eidhof</div>
</div>