<div dir="ltr">Tony,<div><br></div><div>I understand why you&#39;d ideally want to have a real-world benchmark to guide performance optimisations, but if you require that for every performance-related change, you set a very high bar, and that bar will probably have the effect of biasing performance downwards, since if there is no existing benchmark, changes that worsen performance might not get flagged.</div><div><br></div><div>The fact that NSIndexPath got the tagged pointer treatment probably indicates that its implementation has a non-negligible effect on performance (see also <a href="https://twitter.com/Catfish_Man/status/393249511075639296">https://twitter.com/Catfish_Man/status/393249511075639296</a>). </div><div><br></div><div><div>The current IndexPath implementation in terms of an Int array clearly introduces unnecessary overhead in ObjC interop scenarios, so unless this implementation of IndexPath has some benefit I don&#39;t understand, I&#39;d argue that it should be replaced with a straightforward wrapper around an NSIndexPath value.</div></div><div><br></div><div>- Stephan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On 2 August 2016 at 12:12, Tony Parker <span dir="ltr">&lt;<a href="mailto:anthony.parker@apple.com" target="_blank">anthony.parker@apple.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 style="word-wrap:break-word">Hi Stephan,<div><br><div><span class=""><blockquote type="cite"><div>On Aug 2, 2016, at 6:04 PM, Stephan Tolksdorf &lt;<a href="mailto:st@quanttec.com" target="_blank">st@quanttec.com</a>&gt; wrote:</div><br><div><div dir="ltr">Hi Parker,<div><br></div><div>I noticed the IndexPath overhead when I investigated why a Swift 3 implementation of UICollectionViewLayout.layoutAttributesForElementsInRect spent more time in malloc, free and related methods, but I don&#39;t have a benchmark.</div><div><br></div><div>Is it important that IndexPath uses native Swift refcounting? It seems to me that this type is mainly used in ObjC interop code. In native Swift code I would always try to avoid using a dynamically sized, heap allocated array as a data structure index. If NSIndexPath can&#39;t be bridged to a native Swift type without introducing additional overhead, then maybe it shouldn&#39;t be bridged at all?</div><div><br></div><div>- Stephan</div></div></div></blockquote><div><br></div><div><br></div></span><div>I do think it is likely we could figure out some improvements here, but I’d like to start with a concrete test (and something that is representative of real world use cases). If it’s possible to extract something out of what you’ve already done, that would be really helpful. We can also file a bug on <a href="http://bugs.swift.org" target="_blank">bugs.swift.org</a> as a call for help designing a better perf test suite (we need this for all of the types, frankly).</div><div><br></div><div>Once we know we’re measuring the right thing, there are all kinds of interesting things we can do. If (when?) we have ABI stability in Swift 4, we may be able to also change the ObjC Foundation.framework to better cooperate with the Swift side, as we’ll be able to tie the current overlay code to a specific OS instead of having to run back several releases.</div><div><br></div><div>Thanks,</div><div>- Tony</div></div><span class=""><div><br><blockquote type="cite"><div><div dir="ltr"><div><br></div><div class="gmail_extra"><div class="gmail_quote">On 2 August 2016 at 11:09, Tony Parker <span dir="ltr">&lt;<a href="mailto:anthony.parker@apple.com" target="_blank">anthony.parker@apple.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Stephan,<br>
<br>
Do you have some benchmarks that you could share? That would help us focus performance work in the right area.<br>
<br>
I know that 2-item IndexPaths are super common with UIKit collection view and friends, so we may just want to special case those. Unfortunately, NSIndexPath is not abstract, so subclassing it in the same way that we do for a few of the other bridged types (to use native Swift refcounting) is not easy. On the other hand, the ObjC implementation does use tagged pointers, so some NSIndexPaths are really cheap to create.<br>
<br>
- Tony<br>
<div><div><br>
&gt; On Aug 1, 2016, at 11:44 PM, Stephan Tolksdorf via swift-corelibs-dev &lt;<a href="mailto:swift-corelibs-dev@swift.org" target="_blank">swift-corelibs-dev@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Hi,<br>
&gt;<br>
&gt; IndexPath is currently implemented using an [Int] array that is bridged to an NSIndexPath only on demand. Since IndexPath values are primarily used together with Objective-C APIs, wouldn&#39;t it be better to implement IndexPath directly as an NSIndexPath wrapper, in order to avoid the overhead of temporary array instances?<br>
&gt;<br>
&gt; - Stephan<br>
</div></div>&gt; _______________________________________________<br>
&gt; swift-corelibs-dev mailing list<br>
&gt; <a href="mailto:swift-corelibs-dev@swift.org" target="_blank">swift-corelibs-dev@swift.org</a><br>
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-corelibs-dev" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-corelibs-dev</a><br>
<br>
</blockquote></div><br></div></div>
</div></blockquote></div><br></span></div></div></blockquote></div><br></div>