Skip to content

Improve @guaranteed args handling in ARCSequenceOpts #33267

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
Aug 10, 2020

Conversation

meg-gupta
Copy link
Contributor

@meg-gupta meg-gupta commented Aug 3, 2020

@guaranteed args are treated conservatively in ARCSequenceOpts. A function call with a @guaranteed arg is assumed to decrement refcount of the @guaranteed arg.

handleGuaranteedUser transitions conservatively from a Decrement refcount state to MightBeDecremented refcount state on a guaranteed use. Since an apply with a guaranteed arg that does not escape cannot decrement the refcount. This conservative transition is unnecessary. For such cases where the instruction being visited cannot decrement the refcount we should fallback to handleUser which correctly transitions from Decrement refcount state to MightBeUsed for uses where refcount cannot be decremented.

With this change, use swift::mayDecrementRefCount which uses EscapeAnalysis to determine if we need to transition conservatively at the instruction being visited.

@meg-gupta meg-gupta requested a review from atrick August 3, 2020 21:47
@meg-gupta
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Aug 3, 2020

Performance: -O

Regression OLD NEW DELTA RATIO
ObjectiveCBridgeStringHash 80 92 +15.0% 0.87x
StringHashing_latin1 208 226 +8.7% 0.92x
StringHashing_fastPrenormal 600 650 +8.3% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 30 22 -26.7% 1.36x (?)
LessSubstringSubstringGenericComparable 30 22 -26.7% 1.36x
EqualSubstringSubstring 29 22 -24.1% 1.32x (?)
EqualSubstringSubstringGenericEquatable 29 22 -24.1% 1.32x (?)
EqualSubstringString 29 22 -24.1% 1.32x (?)
EqualStringSubstring 30 23 -23.3% 1.30x (?)
UTF8Decode_InitFromCustom_contiguous 168 141 -16.1% 1.19x
UTF8Decode_InitDecoding 167 143 -14.4% 1.17x
StringComparison_longSharedPrefix 372 343 -7.8% 1.08x (?)

Code size: -O

Performance: -Osize

Regression OLD NEW DELTA RATIO
DropWhileArray 29 37 +27.6% 0.78x
DropWhileCountableRangeLazy 58 71 +22.4% 0.82x
DropWhileSequenceLazy 58 71 +22.4% 0.82x
ObjectiveCBridgeStringHash 79 92 +16.5% 0.86x
Breadcrumbs.MutatedIdxToUTF16.Mixed 276 312 +13.0% 0.88x (?)
Breadcrumbs.MutatedUTF16ToIdx.Mixed 271 306 +12.9% 0.89x
StringHashing_latin1 208 226 +8.7% 0.92x (?)
StringHashing_fastPrenormal 600 650 +8.3% 0.92x
 
Improvement OLD NEW DELTA RATIO
LessSubstringSubstring 30 22 -26.7% 1.36x
LessSubstringSubstringGenericComparable 30 22 -26.7% 1.36x
EqualSubstringSubstring 29 22 -24.1% 1.32x
EqualStringSubstring 29 22 -24.1% 1.32x (?)
EqualSubstringSubstringGenericEquatable 29 22 -24.1% 1.32x
EqualSubstringString 29 23 -20.7% 1.26x
DropWhileArrayLazy 53 44 -17.0% 1.20x
StringInterpolationManySmallSegments 10400 8700 -16.3% 1.20x (?)
UTF8Decode_InitDecoding 167 142 -15.0% 1.18x
UTF8Decode_InitFromCustom_contiguous 167 143 -14.4% 1.17x
DropWhileAnyCollectionLazy 164 144 -12.2% 1.14x (?)
DropWhileAnySeqCntRange 122 109 -10.7% 1.12x (?)
DropWhileAnySeqCRangeIter 122 109 -10.7% 1.12x (?)
StringComparison_longSharedPrefix 373 338 -9.4% 1.10x (?)

Code size: -Osize

Performance: -Onone

Regression OLD NEW DELTA RATIO
StringWalk 3040 3640 +19.7% 0.84x
ObjectiveCBridgeStringHash 81 93 +14.8% 0.87x
Breadcrumbs.MutatedUTF16ToIdx.Mixed 288 323 +12.2% 0.89x (?)
Breadcrumbs.MutatedIdxToUTF16.Mixed 293 328 +11.9% 0.89x (?)
StrComplexWalk 4990 5450 +9.2% 0.92x (?)
 
Improvement OLD NEW DELTA RATIO
EqualSubstringSubstringGenericEquatable 33 26 -21.2% 1.27x
EqualSubstringString 35 28 -20.0% 1.25x
LessSubstringSubstringGenericComparable 33 27 -18.2% 1.22x
EqualSubstringSubstring 34 28 -17.6% 1.21x
LessSubstringSubstring 34 28 -17.6% 1.21x
EqualStringSubstring 35 29 -17.1% 1.21x
UTF8Decode_InitDecoding 174 147 -15.5% 1.18x
UTF8Decode_InitFromCustom_contiguous 179 153 -14.5% 1.17x (?)
ArrayAppendLatin1Substring 31572 29016 -8.1% 1.09x (?)
ArrayAppendUTF16Substring 30888 28476 -7.8% 1.08x (?)

Code size: -swiftlibs

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

@meg-gupta
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Aug 4, 2020

Build failed
Swift Test OS X Platform
Git Sha - d372cac1f1954073e5d712bec319cc44d4b7fab2

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

Thanks!!! Just some comment clarification feedback because this code is really hard to makes sense of.

if (!mayDecrementRefCount(PotentialGuaranteedUser, getRCRoot(), AA)) {
return false;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be more clear if the comment explained that by returning, we allow handlePotentialUser to treat this like a normal use and transition to MightBeUsed

It's really too bad that we need to check handlePotentialDecrement again after this, because it's expensive (and confusing). But these helpers are really contorted and I don't know how to fix it.

if (!mayDecrementRefCount(PotentialGuaranteedUser, getRCRoot(), AA)) {
return false;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Same feedback on the comment applies here.

@meg-gupta meg-gupta force-pushed the arcseqchanges branch 2 times, most recently from e38e6ec to de0cc6f Compare August 7, 2020 23:29
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@guaranteed args are treated conservatively in ARCSequenceOpts.
A function call with a @guaranteed arg is assumed to decrement refcount
of the @guaranteed arg. With this change, use
swift::mayDecrementRefCount which uses EscapeAnalysis to determine if we
need to transition conservatively at the instruction being visited.
@swift-ci
Copy link
Contributor

swift-ci commented Aug 7, 2020

Build failed
Swift Test Linux Platform
Git Sha - d372cac1f1954073e5d712bec319cc44d4b7fab2

@swift-ci
Copy link
Contributor

swift-ci commented Aug 7, 2020

Build failed
Swift Test OS X Platform
Git Sha - d372cac1f1954073e5d712bec319cc44d4b7fab2

@meg-gupta
Copy link
Contributor Author

@swift-ci test linux platform

@swift-ci
Copy link
Contributor

swift-ci commented Aug 8, 2020

Build failed
Swift Test Linux Platform
Git Sha - de0cc6fc31cf763d8faeacd13ed44cbfa0f79100

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