Skip to content

Clean up and restructure String bridging a bit #20623

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 29, 2018

Conversation

Catfish-Man
Copy link
Contributor

Initial local benchmarking suggests this isn't a speedup, but I'm curious what the full test suite will say.

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

@Catfish-Man Catfish-Man self-assigned this Nov 16, 2018
@@ -480,7 +483,7 @@ extension String.UTF16View {
internal func _nativeGetIndex(for offset: Int) -> Index {
// Trivial and common: start
if offset == 0 { return startIndex }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had an ASCII fast path here too but I got it wrong and it was crashing. Need to debug further.

return 0
}
defer { _fixLifetime(nativeOther) }
let otherStart = nativeOther.start
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving start to the protocol certainly cleaned this up :)

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeStringIsEqualAllSwift 62 96 +54.8% 0.65x
NSStringConversion 590 894 +51.5% 0.66x
DictionaryBridgeToObjC_Access 1005 1521 +51.3% 0.66x
ObjectiveCBridgeStringIsEqual2 197 293 +48.7% 0.67x
ObjectiveCBridgeStubFromNSString 843 1153 +36.8% 0.73x
ObjectiveCBridgeFromNSStringForced 2353 3162 +34.4% 0.74x
ObjectiveCBridgeStubFromArrayOfNSString2 3595 4592 +27.7% 0.78x
ObjectiveCBridgeFromNSString 1147 1311 +14.3% 0.87x
Improvement
StringEqualPointerComparison 657 600 -8.7% 1.09x
InsertCharacterEndIndex 162 148 -8.6% 1.09x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeStringIsEqualAllSwift 61 97 +59.0% 0.63x
NSStringConversion 588 903 +53.6% 0.65x
ObjectiveCBridgeStringIsEqual2 195 295 +51.3% 0.66x
ObjectiveCBridgeFromNSString 1028 1395 +35.7% 0.74x
Improvement
CStringLongAscii 505 423 -16.2% 1.19x
StringEqualPointerComparison 628 571 -9.1% 1.10x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 647 974 +50.5% 0.66x
ObjectiveCBridgeStringIsEqualAllSwift 63 78 +23.8% 0.81x
ObjectiveCBridgeFromNSStringForced 2442 2823 +15.6% 0.87x
ObjectiveCBridgeStringIsEqual2 196 226 +15.3% 0.87x
ArrayOfPOD 777 859 +10.6% 0.90x (?)
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
--------------

@Catfish-Man Catfish-Man force-pushed the bridgecleanup branch 3 times, most recently from ae46f1b to bc167d4 Compare November 16, 2018 18:26
@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

1 similar comment
@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
StringEqualPointerComparison 600 657 +9.5% 0.91x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 63 55 -12.7% 1.15x
StringBuilderSmallReservingCapacity 427 375 -12.2% 1.14x (?)
StringBuilder 400 365 -8.7% 1.10x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 594 658 +10.8% 0.90x
StringEqualPointerComparison 571 628 +10.0% 0.91x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 61 54 -11.5% 1.13x
StrComplexWalk 6886 6429 -6.6% 1.07x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 660 734 +11.2% 0.90x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 62 55 -11.3% 1.13x
ArrayOfPOD 853 777 -8.9% 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: 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
--------------

@Catfish-Man Catfish-Man changed the title [DNM] Try out some ideas from Michael Ilseman for cleaning up/speeding up bridging further Clean up and restructure String bridging a bit Nov 16, 2018
@Catfish-Man Catfish-Man requested a review from milseman November 16, 2018 19:35
@milseman
Copy link
Member

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 528 589 +11.6% 0.90x
Improvement
UTF8Decode_InitFromBytes_ascii 547 459 -16.1% 1.19x
ObjectiveCBridgeStringIsEqualAllSwift 55 48 -12.7% 1.15x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 520 584 +12.3% 0.89x
FloatingPointPrinting_Float_description_small 4811 5230 +8.7% 0.92x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 54 48 -11.1% 1.12x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
DictionaryKeysContainsNative 53 72 +35.8% 0.74x
CharIteration_japanese_unicodeScalars 128487 162628 +26.6% 0.79x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 55 48 -12.7% 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: 8-Core Intel Xeon E5
  Processor Speed: 3 GHz
  Number of Processors: 1
  Total Number of Cores: 8
  L2 Cache (per Core): 256 KB
  L3 Cache: 25 MB
  Memory: 64 GB
--------------

@Catfish-Man
Copy link
Contributor Author

@swift-ci please benchmark

1 similar comment
@Catfish-Man
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 588 813 +38.3% 0.72x
ObjectiveCBridgeFromNSString 1031 1368 +32.7% 0.75x
ObjectiveCBridgeStubFromNSString 827 1065 +28.8% 0.78x
ObjectiveCBridgeFromNSStringForced 2312 2711 +17.3% 0.85x
ObjectiveCBridgeStringIsEqual2 200 225 +12.5% 0.89x
Improvement
StringEqualPointerComparison 657 600 -8.7% 1.09x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeFromNSString 1000 1483 +48.3% 0.67x
NSStringConversion 580 814 +40.3% 0.71x
ObjectiveCBridgeStubFromNSString 856 1087 +27.0% 0.79x
ObjectiveCBridgeStringIsEqual2 195 221 +13.3% 0.88x
ObjectiveCBridgeStringIsEqualAllSwift 61 67 +9.8% 0.91x
Improvement
StringEqualPointerComparison 628 571 -9.1% 1.10x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
NSStringConversion 640 901 +40.8% 0.71x
ObjectiveCBridgeStubFromNSString 877 1116 +27.3% 0.79x
ArrayOfPOD 782 860 +10.0% 0.91x (?)
ObjectiveCBridgeStringIsEqual2 204 223 +9.3% 0.91x
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
--------------

@Catfish-Man
Copy link
Contributor Author

@swift-ci please benchmark

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

LGTM

return _cocoaGetCStringTrampoline(self,
outputPtr,
maxLength,
encoding)
Copy link
Member

Choose a reason for hiding this comment

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

Style would be to line-break after opening delimiter, and try to fit these all on the next line

@@ -190,7 +187,7 @@ final internal class _StringStorage: _AbstractStringStorage {
internal var _reserved: UInt16

@inlinable
Copy link
Member

Choose a reason for hiding this comment

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

Huh, unrelated to your PR, but this @inlinable can be dropped.

#20651

@Catfish-Man
Copy link
Contributor Author

@swift-ci please benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeFromNSString 1022 1395 +36.5% 0.73x
Improvement
StringEqualPointerComparison 657 600 -8.7% 1.09x
ObjectiveCBridgeStringIsEqualAllSwift 62 57 -8.1% 1.09x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
ObjectiveCBridgeFromNSString 1153 1289 +11.8% 0.89x
PrefixWhileAnySeqCntRangeLazy 159 176 +10.7% 0.90x
Improvement
StringEqualPointerComparison 628 571 -9.1% 1.10x
ObjectiveCBridgeStringIsEqualAllSwift 61 57 -6.6% 1.07x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
ArrayOfPOD 778 857 +10.2% 0.91x (?)
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
--------------

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

1 similar comment
@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
InsertCharacterEndIndex 146 160 +9.6% 0.91x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 62 47 -24.2% 1.32x
ObjectiveCBridgeStringIsEqual2 198 174 -12.1% 1.14x
Hanoi 3764 3484 -7.4% 1.08x
NSStringConversion 612 570 -6.9% 1.07x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 61 46 -24.6% 1.33x
ObjectiveCBridgeStringIsEqual2 197 174 -11.7% 1.13x
NSStringConversion 609 564 -7.4% 1.08x (?)

Performance: -Onone

TEST OLD NEW DELTA RATIO
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 64 49 -23.4% 1.31x
Histogram 5992 5149 -14.1% 1.16x
ObjectiveCBridgeStringIsEqual2 206 182 -11.7% 1.13x
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
--------------

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

1 similar comment
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

1 similar comment
@Catfish-Man
Copy link
Contributor Author

@swift-ci please test and merge

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke test

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke test

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke benchmark

@swift-ci
Copy link
Contributor

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 62 47 -24.2% 1.32x
ObjectiveCBridgeStringIsEqual2 187 164 -12.3% 1.14x
NSStringConversion 600 545 -9.2% 1.10x (?)
InsertCharacterEndIndexNonASCII 61 56 -8.2% 1.09x (?)

Performance: -Osize

TEST OLD NEW DELTA RATIO
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 67 47 -29.9% 1.43x
ObjectiveCBridgeStringIsEqual2 189 164 -13.2% 1.15x

Performance: -Onone

TEST OLD NEW DELTA RATIO
Regression
ExclusivityIndependent 75 84 +12.0% 0.89x
Improvement
ObjectiveCBridgeStringIsEqualAllSwift 62 47 -24.2% 1.32x
DropFirstSequenceLazy 12021 10320 -14.2% 1.16x
DropFirstAnySequenceLazy 13119 11434 -12.8% 1.15x
ObjectiveCBridgeStringIsEqual2 188 167 -11.2% 1.13x
DropFirstSequence 11710 10428 -10.9% 1.12x
DropWhileAnySequenceLazy 14062 12843 -8.7% 1.09x
DropFirstAnySequence 12484 11435 -8.4% 1.09x
DropWhileSequence 15253 13990 -8.3% 1.09x
NSStringConversion 654 600 -8.3% 1.09x
PrefixAnySequenceLazy 9383 8617 -8.2% 1.09x
PrefixSequenceLazy 9033 8298 -8.1% 1.09x
PrefixSequence 9090 8393 -7.7% 1.08x
DropWhileSequenceLazy 13627 12619 -7.4% 1.08x
PrefixAnySequence 9801 9085 -7.3% 1.08x
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
--------------

• 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
@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke test and merge

@Catfish-Man
Copy link
Contributor Author

Catfish-Man commented Nov 29, 2018

the ABI diffs are due to https://bugs.swift.org/browse/SR-9372

@Catfish-Man
Copy link
Contributor Author

@swift-ci please smoke test and merge

@swift-ci swift-ci merged commit e012655 into swiftlang:master Nov 29, 2018
@Catfish-Man
Copy link
Contributor Author

@airspeedswift we may want this for Swift 5, not so much because of the perf win (though that's nice), but because it'll make cherry-picking other bridging changes hard if we don't

@Catfish-Man Catfish-Man deleted the bridgecleanup branch December 1, 2018 00:51
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.

3 participants