After a bit more investigation, I found that if you replace the following code:<p><pre><code>  result.append(begin == eos ? &quot;&quot; : String(cs[begin..&lt;end.successor()]))
</code></pre>
with this:<p><pre><code>  if begin == eos {
    result.append(&quot;&quot;)
  } else if let str = String(cs[begin..&lt;end.successor()]) {
    result.append(str)
  }
</code></pre>
runtime goes down from ~3 seconds to ~2.2 seconds.<p>This is due to a rather insidious API design decision:<p><pre><code>  init?(_ view: String.UTF16View)
</code></pre>
constructs a string out of a UTF16 view, but it can fail. If used in a context where its type is inferred to be non-nullable, the following generic reflection-related init is used instead:<p><pre><code>  init&lt;T&gt;(_ instance: T)
</code></pre>
I&#x27;m going to bring this up on the list and see if there are better ways of doing things.<p>As far as I can tell most of the rest of the time is spent in the Swift native Unicode --&gt; UTF16 decoding machinery, and NSCharacterSet.