<div dir="ltr">Thanks to all who commented. I&#39;ll put together a proposal to rename that initializer tonight, unless someone else wants to do it. This seems like a pretty straightforward clarity gain, and it might even help a bit with compilation times.<div><br></div><div>Austin</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 9, 2016 at 10:54 AM, Daniel Dunbar via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@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 style="word-wrap:break-word"><br><div><span class=""><blockquote type="cite"><div>On May 9, 2016, at 10:28 AM, Jacob Bandes-Storch via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, May 9, 2016 at 10:25 AM, Joe Groff via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@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"><span><br>
&gt; On May 7, 2016, at 10:39 AM, Austin Zheng via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt; Hello Swift users,<br>
&gt;<br>
&gt; I wanted to run something past you folks and get some opinions/feedback.<br>
&gt;<br>
&gt; About a month ago on Hacker News I saw someone commenting about how Swift&#39;s string-handling code was unbearably slow (3 seconds to run a code sample, vs. 0.8 in Java). I asked him to provide the code, and he obliged. Unfortunately, I didn&#39;t have time to dig into it until this morning. The code in its entirety can be found here: <a href="https://gist.github.com/austinzheng/d6c674780a58cb63832c4df3f809e683" rel="noreferrer" target="_blank">https://gist.github.com/austinzheng/d6c674780a58cb63832c4df3f809e683</a><br>
&gt;<br>
&gt; At line 26 we have the following code:<br>
&gt;<br>
&gt; result.append(begin == eos ? &quot;&quot; : String(cs[begin..&lt;end.successor()]))<br>
&gt;<br>
&gt; &#39;cs&#39; is a UTF16 view into an input string, while &#39;result&#39; is a [String]. When I profiled the code in Instruments, I noticed that it was spending significant time within the reflection machinery.<br>
&gt;<br>
&gt; It turns out that the initializer to make a String out of a utf16 view looks like this, and I believe this is the initializer the author intended to call:<br>
&gt;<br>
&gt; init?(_: String.UTF16View)<br>
&gt;<br>
&gt; However, the actual initializer being called was this String initializer in the Mirror code:<br>
&gt;<br>
&gt; public init&lt;Subject&gt;(_ instance: Subject)<br>
&gt;<br>
&gt; This seems like a tricky gotcha for developers who aren&#39;t extremely familiar with both the String and reflection APIs. His code looked reasonable at a first glance and I didn&#39;t suspect anything was wrong until I profiled it. Even so, I only made the connection because I recognized the name of the standard library function from poking around inside the source files.<br>
&gt;<br>
&gt; What do other people think? Is this something worth worrying about, or is it so rare that it shouldn&#39;t matter? Also, any suggestions as to how that code sample might be improved would be appreciated - my naive first attempt wasn&#39;t any better.<br>
<br>
</span>This definitely strikes me as a problem. The String&lt;T&gt;(_:) constructor is very easy to call by accident if you&#39;re trying to hit another unlabeled initializer. It also strikes me as not particularly &quot;value-preserving&quot;, since stringifying many types loses information. Perhaps we should propose giving it a label, String(printing:) maybe?<br></blockquote><div><br></div><div>+1</div></div></div></div></div></blockquote><div><br></div></span>+1</div><div><br></div><div> - Daniel</div><span class=""><div><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-Joe<br>
<div><div>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
</div></div></blockquote></div><br></div></div>
_______________________________________________<br>swift-users mailing list<br><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br></div></blockquote></div><br></span></div><br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br></div>