Skip to content

Fix ExistentialSpecializer to correctly cleanup storage. #25038

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 7 commits into from
Jun 3, 2019
Merged

Fix ExistentialSpecializer to correctly cleanup storage. #25038

merged 7 commits into from
Jun 3, 2019

Conversation

atrick
Copy link
Contributor

@atrick atrick commented May 24, 2019

Handle calling conventions and cleanups in all the places (hopefully).

  • when ExistentialSpecializer copies the specialized concrete arg into the
    original existential value
  • when ExistentialSpecializer generates a think
  • when SILCombine substitutes concrete values in place of the opened
    existential.

One particularly nasty problem is the existential boxes need to be
destroyed. It is not ok to simply destroy their value. The "leaks"
tool does not catch this problem.

Ownership SIL will make this all much more robust.

Fixes rdar://problem/50595630 Multiple leaks detected - Swift Perf

atrick added 7 commits May 23, 2019 17:20
Minor drive-by fix. Use best practice when generating debug locations.

Use the scope and location from the insertion point. But since we
can't attach a return location to a normal instruction, use a compiler
generated placeholder.
This option no longer works but was still in the option file and help
message.

Add a temporary pass-specific option instead for debugging until this
pass has been sufficiently tested yet.
Factor the code a bit and follow some best practices so that it's
easier for me to work with in preparation for a bug fix.
This reindented a lot of the code. It only ran on the function that I
modified.
Handle calling conventions and cleanups in all the places (hopefully).
- when ExistentialSpecializer copies the specialized concrete arg into the
original existential value
- when ExistentialSpecializer generates a think
- when SILCombine substitutes concrete values in place of the opened
existential.

One particularly nasty problem is the existential boxes need to be
destroyed. It is not ok to simply destroy their value. The "leaks"
tool does not catch this problem.

Ownership SIL will make this all much more robust.

Fixes <rdar://problem/50595630> Multiple leaks detected - Swift Perf
@atrick atrick requested a review from rajbarik May 24, 2019 00:23
@atrick
Copy link
Contributor Author

atrick commented May 24, 2019

@swift-ci test.

@atrick
Copy link
Contributor Author

atrick commented May 24, 2019

@swift-ci test source compatibility

@atrick
Copy link
Contributor Author

atrick commented May 24, 2019

@swift-ci benchmark

@swift-ci
Copy link
Contributor

Performance: -O

TEST OLD NEW DELTA RATIO
Regression
SortLargeExistentials 6600 16300 +147.0% 0.40x
StackPromo 12800 14100 +10.2% 0.91x
Improvement
BucketSort 2531 150 -94.1% 16.87x
ProtocolDispatch2 207 76 -63.3% 2.72x
ObserverForwarderStruct 660 575 -12.9% 1.15x (?)
ObserverUnappliedMethod 1710 1510 -11.7% 1.13x (?)
DataAccessBytesMedium 47 43 -8.5% 1.09x (?)

Code size: -O

TEST OLD NEW DELTA RATIO
Regression
BucketSort.o 11050 11618 +5.1% 0.95x
NIOChannelPipeline.o 4218 4357 +3.3% 0.97x
StackPromo.o 1892 1939 +2.5% 0.98x
Improvement
ProtocolDispatch2.o 1940 1740 -10.3% 1.11x
ObserverForwarderStruct.o 3728 3648 -2.1% 1.02x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
SortLargeExistentials 6700 16200 +141.8% 0.41x
ProtocolDispatch2 206 326 +58.3% 0.63x
DropLastCountableRangeLazy 4 5 +25.0% 0.80x (?)
DropLastAnyCollection 28 33 +17.9% 0.85x (?)
StackPromo 13000 14500 +11.5% 0.90x
PrefixAnyCollection 81 88 +8.6% 0.92x (?)
PrefixWhileAnySequence 1194 1288 +7.9% 0.93x (?)
Improvement
BucketSort 2523 145 -94.3% 17.40x
SuffixCountableRangeLazy 5 4 -20.0% 1.25x (?)
ObserverForwarderStruct 710 585 -17.6% 1.21x (?)
DropFirstAnyCollection 103 86 -16.5% 1.20x
ObserverUnappliedMethod 1740 1520 -12.6% 1.14x (?)
ReversedDictionary2 239 217 -9.2% 1.10x (?)
DataAccessBytesMedium 58 54 -6.9% 1.07x (?)

Code size: -Osize

TEST OLD NEW DELTA RATIO
Regression
NIOChannelPipeline.o 3651 3963 +8.5% 0.92x
ProtocolDispatch2.o 1968 2084 +5.9% 0.94x
BucketSort.o 11159 11431 +2.4% 0.98x
Improvement
ObserverForwarderStruct.o 3908 3708 -5.1% 1.05x
ObserverUnappliedMethod.o 5563 5354 -3.8% 1.04x
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: 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

@atrick
Copy link
Contributor Author

atrick commented May 24, 2019

I cannot reproduce the SortLargeExistentials regression locally. It only showed up in Osize which usually indicates something wasn't inlined.

@rajbarik will you have a chance to review these changes?

@rajbarik
Copy link
Contributor

@atrick Sorry, I got sidetracked with something and did not see the email until now. I will have a look at it today.

@rajbarik rajbarik merged commit d402077 into swiftlang:master Jun 3, 2019
dan-zheng added a commit that referenced this pull request Jun 11, 2019
This reverts commit d402077, reversing
changes made to 651045f.
@atrick atrick deleted the fix-specializer-leak branch July 30, 2019 23: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