Improve AttributedString.CharacterView to Substring conversion in AttributedStringProtocol.range(of:) #1440
+6
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We don't currently have
range(of:)
implemented natively onBigString
(or a UTF-8 collection) and instead we must first convert to aSubstring
to perform the searching operation. In the future, we should benchmark and improve this function by writing it natively on theBigString
storage instead of bridging toString
. However, today we're taking a very slow, linear path of converting the character view to aSubstring
iterating character by character. Instead, we can take a faster path by using ourCharacterView
toString
conversion that copies chunk-by-chunk and create aSubstring
from that result. The benchmarks show that this has a significant performance improvement over the existing implementation (with much more room to improve with a native implementation)AttributedStringBenchmarks
range(of:) metrics
Time (wall clock): results within specified thresholds, fold down for details.
Time (total CPU): results within specified thresholds, fold down for details.
Throughput (# / s): results within specified thresholds, fold down for details.
Resolves rdar://155952423