Skip to content

[String] ASCII fast-path for UTF16View #20848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 30, 2018

Conversation

milseman
Copy link
Member

Add an isASCII fast-path for many UTF16View operations. These are
heavily utilized in random-access scenarios, allowing us to both be
more efficient and skip generating breadcrumbs for ASCII strings.

@milseman
Copy link
Member Author

@swift-ci please test

@milseman
Copy link
Member Author

@swift-ci please benchmark

@milseman milseman requested a review from Catfish-Man November 29, 2018 00:30
@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
Breadcrumbs.MutatedIdxToUTF16.Mixed 259 284 +9.7% 0.91x
Breadcrumbs.IdxToUTF16Range.longMixed 372 405 +8.9% 0.92x
Breadcrumbs.IdxToUTF16.longMixed 712 771 +8.3% 0.92x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 261 282 +8.0% 0.93x
Improvement
Breadcrumbs.MutatedIdxToUTF16.ASCII 761 4 -99.5% 190.20x
Breadcrumbs.MutatedUTF16ToIdx.ASCII 757 4 -99.5% 189.20x
Breadcrumbs.IdxToUTF16Range.longASCII 290 32 -89.0% 9.06x
Breadcrumbs.IdxToUTF16.longASCII 594 137 -76.9% 4.34x
Breadcrumbs.UTF16ToIdxRange.longASCII 84 26 -69.0% 3.23x
Breadcrumbs.UTF16ToIdx.longASCII 311 137 -55.9% 2.27x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 47 24 -48.9% 1.96x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
Breadcrumbs.MutatedIdxToUTF16.Mixed 258 284 +10.1% 0.91x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 259 285 +10.0% 0.91x
Breadcrumbs.IdxToUTF16Range.longMixed 372 404 +8.6% 0.92x
Breadcrumbs.IdxToUTF16.longMixed 710 767 +8.0% 0.93x
Improvement
Breadcrumbs.MutatedIdxToUTF16.ASCII 760 4 -99.5% 189.95x
Breadcrumbs.MutatedUTF16ToIdx.ASCII 755 4 -99.5% 188.70x
Breadcrumbs.IdxToUTF16Range.longASCII 291 34 -88.3% 8.56x
Breadcrumbs.IdxToUTF16.longASCII 579 138 -76.2% 4.20x
Breadcrumbs.UTF16ToIdxRange.longASCII 84 28 -66.7% 3.00x
Breadcrumbs.UTF16ToIdx.longASCII 310 138 -55.5% 2.25x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 47 24 -48.9% 1.96x
InsertCharacterEndIndex 163 149 -8.6% 1.09x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
Breadcrumbs.MutatedUTF16ToIdx.Mixed 269 298 +10.8% 0.90x
Breadcrumbs.MutatedIdxToUTF16.Mixed 265 292 +10.2% 0.91x
Improvement
Breadcrumbs.MutatedIdxToUTF16.ASCII 769 12 -98.4% 64.08x
Breadcrumbs.MutatedUTF16ToIdx.ASCII 768 12 -98.4% 63.99x
Breadcrumbs.IdxToUTF16Range.longASCII 429 163 -62.0% 2.63x
Breadcrumbs.IdxToUTF16.longASCII 1181 715 -39.5% 1.65x
Breadcrumbs.UTF16ToIdxRange.longASCII 216 154 -28.7% 1.40x
Breadcrumbs.UTF16ToIdx.longASCII 905 709 -21.7% 1.28x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 116 92 -20.7% 1.26x
ExclusivityIndependent 86 75 -12.8% 1.15x
How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB
--------------

Copy link
Contributor

@Catfish-Man Catfish-Man left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. I probably mid-air collided part of it with the PR I just landed though; sorry!

@gottesmm
Copy link
Contributor

Nice!

@milseman
Copy link
Member Author

That's fine, I'll roll in the (less important but still a nice 30%) ASCII fast-path in _nativeCopyUTF16CodeUnits too.

@milseman
Copy link
Member Author

@swift-ci please benchmark

@milseman
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 4e63bd906e89ef167f0d1482706f00bc283ed689

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 4e63bd906e89ef167f0d1482706f00bc283ed689

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
Breadcrumbs.MutatedIdxToUTF16.Mixed 256 284 +10.9% 0.90x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 259 286 +10.4% 0.91x
Improvement
Breadcrumbs.MutatedUTF16ToIdx.ASCII 755 4 -99.5% 188.70x
Breadcrumbs.UTF16ToIdxRange.longASCII 83 27 -67.5% 3.07x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 50 19 -62.0% 2.63x
Breadcrumbs.UTF16ToIdx.longASCII 311 137 -55.9% 2.27x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
Breadcrumbs.MutatedIdxToUTF16.Mixed 258 285 +10.5% 0.91x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 262 287 +9.5% 0.91x
Improvement
Breadcrumbs.MutatedUTF16ToIdx.ASCII 757 4 -99.5% 189.20x
Breadcrumbs.UTF16ToIdxRange.longASCII 84 28 -66.7% 3.00x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 50 19 -62.0% 2.63x
Breadcrumbs.UTF16ToIdx.longASCII 323 138 -57.3% 2.34x
ObjectiveCBridgeFromNSArrayAnyObjectToString 55870 47802 -14.4% 1.17x
EqualStringSubstring 13 12 -7.7% 1.08x (?)

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
Breadcrumbs.MutatedUTF16ToIdx.ASCII 794 23 -97.1% 34.52x
How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: 12-Core Intel Xeon E5
  Processor Speed: 2.7 GHz
  Number of Processors: 1
  Total Number of Cores: 12
  L2 Cache (per Core): 256 KB
  L3 Cache: 30 MB
  Memory: 64 GB
--------------

Add an isASCII fast-path for many UTF16View operations. These are
heavily utilized in random-access scenarios, allowing us to both be
more efficient and skip generating breadcrumbs for ASCII strings.
@milseman
Copy link
Member Author

@swift-ci please test

@milseman
Copy link
Member Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 2a46550fdf5e75603c0a38ed1a7f57931ade116e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 2a46550fdf5e75603c0a38ed1a7f57931ade116e

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
Breadcrumbs.MutatedIdxToUTF16.Mixed 234 259 +10.7% 0.90x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 236 260 +10.2% 0.91x
Improvement
Breadcrumbs.MutatedUTF16ToIdx.ASCII 685 4 -99.4% 171.21x
Breadcrumbs.UTF16ToIdxRange.longASCII 82 24 -70.7% 3.42x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 48 16 -66.7% 3.00x
Breadcrumbs.UTF16ToIdx.longASCII 274 123 -55.1% 2.23x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
StringComparison_abnormal 7972 8929 +12.0% 0.89x
Breadcrumbs.MutatedIdxToUTF16.Mixed 232 259 +11.6% 0.90x
Improvement
Breadcrumbs.MutatedUTF16ToIdx.ASCII 685 4 -99.4% 171.21x
Breadcrumbs.UTF16ToIdxRange.longASCII 82 25 -69.5% 3.28x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 49 16 -67.3% 3.06x
Breadcrumbs.UTF16ToIdx.longASCII 277 124 -55.2% 2.23x
StringEqualPointerComparison 564 512 -9.2% 1.10x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
Breadcrumbs.MutatedUTF16ToIdx.ASCII 720 22 -96.9% 32.73x
Breadcrumbs.CopyUTF16CodeUnits.ASCII 205 169 -17.6% 1.21x
ArrayOfPOD 764 692 -9.4% 1.10x
How to read the data The tables contain differences in performance which are larger than 8% and differences in code size which are larger than 1%.

If you see any unexpected regressions, you should consider fixing the
regressions before you merge the PR.

Noise: Sometimes the performance results (not code size!) contain false
alarms. Unexpected regressions which are marked with '(?)' are probably noise.
If you see regressions which you cannot explain you can try to run the
benchmarks again. If regressions still show up, please consult with the
performance team (@eeckstein).

Hardware Overview
  Model Name: Mac Pro
  Model Identifier: MacPro6,1
  Processor Name: Quad-Core Intel Xeon E5
  Processor Speed: 3.7 GHz
  Number of Processors: 1
  Total Number of Cores: 4
  L2 Cache (per Core): 256 KB
  L3 Cache: 10 MB
  Memory: 16 GB
--------------

@milseman milseman merged commit c3c6fdc into swiftlang:master Nov 30, 2018
@milseman milseman deleted the ascii_hotness branch November 30, 2018 02:19
milseman added a commit to milseman/swift that referenced this pull request Nov 30, 2018
Add an isASCII fast-path for many UTF16View operations. These are
heavily utilized in random-access scenarios, allowing us to both be
more efficient and skip generating breadcrumbs for ASCII strings.
airspeedswift pushed a commit that referenced this pull request Dec 1, 2018
* Assorted bridging changes:
• Convert _AbstractStringStorage to a protocol, and the free functions used to deduplicate implementations to extensions on that protocol.
• Move 'start' into the abstract type and use that to simplify some code
• Move the ASCII fast path for length into UTF16View.
• Add a weirder but faster way to check which (if any) of our NSString subclasses a given object is, and adopt it

(cherry picked from commit 8b57921)

* [String] ASCII fast-path for UTF16View (#20848)

Add an isASCII fast-path for many UTF16View operations. These are
heavily utilized in random-access scenarios, allowing us to both be
more efficient and skip generating breadcrumbs for ASCII strings.
PopFlamingo pushed a commit to PopFlamingo/swift that referenced this pull request Dec 6, 2018
Add an isASCII fast-path for many UTF16View operations. These are
heavily utilized in random-access scenarios, allowing us to both be
more efficient and skip generating breadcrumbs for ASCII strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants