Skip to content

[semantic-arc] Eliminate simple recursive copy without borrows involved. #34812

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

Conversation

gottesmm
Copy link
Contributor

This doesn't happen as much as the guaranteed + owned value optimization but can
occur once we start eliminating borrow scopes. I noticed that I needed this when
looking at the arbitrary RAUW for ownership API.

@gottesmm gottesmm requested review from atrick and meg-gupta November 18, 2020 21:31
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci test source compatibility

@gottesmm
Copy link
Contributor Author

@swift-ci smoke benchmark

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 37628233612dfef8505bef2496ad08a99ea38240

@atrick
Copy link
Contributor

atrick commented Nov 18, 2020

@gottesmm is this another workaround for not enabling CopyPropagation? Can we tag these somehow so we can remove all the ad-hoc complexity later?

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 37628233612dfef8505bef2496ad08a99ea38240

@swift-ci
Copy link
Contributor

Build failed before running benchmark.

@gottesmm
Copy link
Contributor Author

This needs #34809

@gottesmm
Copy link
Contributor Author

I just added the commit from 34809 on top.

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci smoke benchmark

@gottesmm
Copy link
Contributor Author

@swift-ci test source compatibility

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
StringFromLongWholeSubstring 4 5 +25.0% 0.80x
InsertCharacterEndIndexNonASCII 59 65 +10.2% 0.91x (?)
NSStringConversion.MutableCopy.Rebridge.Long 1081 1169 +8.1% 0.92x (?)
FloatingPointPrinting_Float_description_small 5400 5832 +8.0% 0.93x (?)
InsertCharacterEndIndex 165 178 +7.9% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
PrefixAnySequence 2316 1372 -40.8% 1.69x
DropWhileAnySequence 2811 1830 -34.9% 1.54x
DropFirstAnySequence 2797 1833 -34.5% 1.53x
NSStringConversion.UTF8 1033 934 -9.6% 1.11x (?)
FlattenListFlatMap 6659 6117 -8.1% 1.09x (?)
AngryPhonebook.Strasse.Small 1022 949 -7.1% 1.08x (?)
ObjectiveCBridgeStringHash 114 106 -7.0% 1.08x (?)
DataToStringLargeUnicode 7400 6900 -6.8% 1.07x (?)
NSStringConversion.MutableCopy.Rebridge.Medium 640 598 -6.6% 1.07x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
StringFromLongWholeSubstring 4 5 +25.0% 0.80x
DropFirstAnySeqCRangeIter 164 199 +21.3% 0.82x
DropFirstAnySeqCntRange 164 199 +21.3% 0.82x
DropWhileAnyCollection 182 217 +19.2% 0.84x
DropWhileAnySeqCntRange 178 201 +12.9% 0.89x
DropWhileAnySeqCRangeIter 195 219 +12.3% 0.89x (?)
DropFirstAnySeqCRangeIterLazy 225 252 +12.0% 0.89x (?)
DropFirstAnySeqCntRangeLazy 225 251 +11.6% 0.90x (?)
PrefixAnyCollection 165 183 +10.9% 0.90x
DropFirstAnyCollection 165 182 +10.3% 0.91x (?)
DropWhileAnyCollectionLazy 252 276 +9.5% 0.91x (?)
DropWhileAnySeqCRangeIterLazy 247 270 +9.3% 0.91x
DropWhileAnySeqCntRangeLazy 247 270 +9.3% 0.91x
SuffixAnyCollection 65 71 +9.2% 0.92x (?)
DropLastAnyCollection 65 71 +9.2% 0.92x (?)
PrefixWhileAnyCollection 218 235 +7.8% 0.93x (?)
 
Improvement OLD NEW DELTA RATIO
DropWhileAnySequence 3191 2074 -35.0% 1.54x
DropFirstAnySequence 5712 4583 -19.8% 1.25x
DropWhileSequenceLazy 123 105 -14.6% 1.17x
PrefixAnySequence 6112 5356 -12.4% 1.14x
PrefixAnySeqCRangeIter 193 175 -9.3% 1.10x
UTF8Decode_InitFromData_ascii_as_ascii 673 615 -8.6% 1.09x (?)

Code size: -Osize

Improvement OLD NEW DELTA RATIO
DropWhile.o 16226 15773 -2.8% 1.03x

Performance: -Onone

Regression OLD NEW DELTA RATIO
RandomDoubleDef 93400 105300 +12.7% 0.89x (?)
RandomDoubleLCG 57750 64284 +11.3% 0.90x (?)
 
Improvement OLD NEW DELTA RATIO
StringToDataEmpty 4750 3900 -17.9% 1.22x (?)
StringToDataSmall 4850 4000 -17.5% 1.21x (?)
DataToStringMedium 11650 9950 -14.6% 1.17x (?)
StringInterpolation 17600 16000 -9.1% 1.10x (?)
DataAppendDataMediumToSmall 6440 5940 -7.8% 1.08x (?)
DictionaryRemoveOfObjects 61000 56400 -7.5% 1.08x (?)
ArrayOfPOD 1131 1047 -7.4% 1.08x (?)

Code size: -swiftlibs

Improvement OLD NEW DELTA RATIO
libswiftFoundation.dylib 1359872 1343488 -1.2% 1.01x
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

@gottesmm
Copy link
Contributor Author

@swift-ci test windows platform

@gottesmm
Copy link
Contributor Author

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

@atrick interesting... this one seemed to hit code-size on DropWhile.o. Thats real ARC traffic being eliminated. Also some stuff in Foundation.

SmallVector<Operand *, 8> parentLifetimeEndingUses;
for (auto *origValueUse : originalValue->getUses())
if (origValueUse->isLifetimeEnding() &&
!isa<OwnershipForwardingInst>(origValueUse->getUser()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm... reading this... I think what I wrote here could be made better. I think at this point, the optimization is not dealing with LiveRanges, so the right thing to do is just gather up all consuming uses of the value, ignoring forwarding.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

*ignoring forwarding I mean just treating forwarding insts as normal consuming instructions.

@swift-ci
Copy link
Contributor

Performance: -O

Regression OLD NEW DELTA RATIO
FlattenListLoop 1004 1545 +53.9% 0.65x (?)
FlattenListFlatMap 3204 4440 +38.6% 0.72x (?)
PrefixSequenceLazy 22 26 +18.2% 0.85x
PrefixSequence 22 26 +18.2% 0.85x
 
Improvement OLD NEW DELTA RATIO
PrefixAnySequence 1835 1046 -43.0% 1.75x
DropWhileAnySequence 2211 1394 -37.0% 1.59x
DropFirstAnySequence 2171 1390 -36.0% 1.56x
DropWhileArrayLazy 58 49 -15.5% 1.18x (?)
IterateData 944 803 -14.9% 1.18x (?)
ObjectiveCBridgeStringHash 70 64 -8.6% 1.09x (?)
ObjectiveCBridgeFromNSDictionaryAnyObject 25800 23900 -7.4% 1.08x (?)
DropWhileArray 28 26 -7.1% 1.08x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
PrefixArray 13 26 +100.0% 0.50x
DropWhileArrayLazy 49 71 +44.9% 0.69x
PrefixCountableRangeLazy 18 26 +44.4% 0.69x
PrefixSequenceLazy 40 53 +32.5% 0.75x
PrefixSequence 40 53 +32.5% 0.75x
DropFirstSequence 40 50 +25.0% 0.80x
DropFirstSequenceLazy 40 50 +25.0% 0.80x
PrefixWhileAnyCollection 113 139 +23.0% 0.81x
DropLastAnyCollection 35 41 +17.1% 0.85x
DropFirstAnyCollection 86 99 +15.1% 0.87x (?)
 
Improvement OLD NEW DELTA RATIO
DropFirstArray 26 13 -50.0% 2.00x
DropFirstArrayLazy 26 14 -46.2% 1.86x
DropFirstCountableRangeLazy 26 16 -38.5% 1.62x
DropWhileAnySequence 2423 1650 -31.9% 1.47x
PrefixWhileAnyCollectionLazy 108 81 -25.0% 1.33x (?)
PrefixWhileAnySeqCRangeIterLazy 107 81 -24.3% 1.32x (?)
PrefixWhileAnySeqCntRangeLazy 107 81 -24.3% 1.32x (?)
DropWhileSequenceLazy 81 62 -23.5% 1.31x
DropFirstAnySequence 4121 3295 -20.0% 1.25x
PrefixAnySeqCRangeIterLazy 101 81 -19.8% 1.25x (?)
PrefixAnySeqCntRangeLazy 101 81 -19.8% 1.25x (?)
PrefixAnyCollection 109 89 -18.3% 1.22x
DropWhileCountableRangeLazy 71 58 -18.3% 1.22x
FlattenListLoop 1207 999 -17.2% 1.21x (?)
DropFirstAnySeqCRangeIterLazy 143 119 -16.8% 1.20x
DropFirstAnySeqCntRangeLazy 143 119 -16.8% 1.20x (?)
PrefixAnySequence 4565 3805 -16.6% 1.20x
IterateData 940 803 -14.6% 1.17x
SuffixAnyCollection 41 37 -9.8% 1.11x (?)
DropWhileAnySeqCRangeIter 109 100 -8.3% 1.09x (?)
ObjectiveCBridgeStringHash 69 64 -7.2% 1.08x (?)
DropLastAnySeqCRangeIterLazy 49800 46220 -7.2% 1.08x (?)

Code size: -Osize

Improvement OLD NEW DELTA RATIO
DropWhile.o 16226 15773 -2.8% 1.03x

Performance: -Onone

Regression OLD NEW DELTA RATIO
ArrayAppendLatin1Substring 28692 31284 +9.0% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
DropWhileAnySeqCntRangeLazy 53299 48439 -9.1% 1.10x (?)
DropLastAnySeqCRangeIterLazy 51874 47524 -8.4% 1.09x (?)
AngryPhonebook.Cyrillic 168 154 -8.3% 1.09x (?)
AngryPhonebook.Armenian 156 143 -8.3% 1.09x (?)
Data.hash.Empty 145 133 -8.3% 1.09x (?)
AngryPhonebook.Cyrillic.Small 622 574 -7.7% 1.08x (?)
AngryPhonebook.Armenian.Small 622 575 -7.6% 1.08x (?)
DropLastAnyCollection 12605 11683 -7.3% 1.08x (?)
DropWhileAnySeqCntRange 54409 50453 -7.3% 1.08x (?)
AngryPhonebook.Strasse.Small 727 675 -7.2% 1.08x (?)
DropLastAnySeqCRangeIter 50366 46773 -7.1% 1.08x (?)
AngryPhonebook.Strasse 136 127 -6.6% 1.07x (?)
DropFirstAnySeqCRangeIter 50235 46913 -6.6% 1.07x (?)

Code size: -swiftlibs

Improvement OLD NEW DELTA RATIO
libswiftFoundation.dylib 1359872 1343488 -1.2% 1.01x
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 mini
  Model Identifier: Macmini8,1
  Processor Name: 6-Core Intel Core i7
  Processor Speed: 3.2 GHz
  Number of Processors: 1
  Total Number of Cores: 6
  L2 Cache (per Core): 256 KB
  L3 Cache: 12 MB
  Memory: 64 GB

@gottesmm gottesmm force-pushed the pr-b1ab03067e8684c69df8ad52319746f5b9d145e0 branch from 4603e72 to b9b6eea Compare November 20, 2020 02:00
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

This doesn't happen as much as the guaranteed + owned value optimization but can
occur once we start eliminating borrow scopes. I noticed that I needed this when
looking at the arbitrary RAUW for ownership API.
@gottesmm gottesmm force-pushed the pr-b1ab03067e8684c69df8ad52319746f5b9d145e0 branch from b9b6eea to 1fd4003 Compare November 20, 2020 06:44
@gottesmm
Copy link
Contributor Author

Just had to mixup a merge conflict due to me landing a different PR that touched the same test.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm merged commit 7bb9aa7 into swiftlang:main Nov 20, 2020
@gottesmm gottesmm deleted the pr-b1ab03067e8684c69df8ad52319746f5b9d145e0 branch November 20, 2020 09:06
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