Skip to content

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented Mar 9, 2020

Otherwise in call frames like the one in the test in this commit get unneeded
ARC traffic. We should never pessimize read only code that doesnt need
side-effects with side-effects if we can avoid it.

I am seeing this a bunch when I look at SIL from projects that use a lot of
protocols. Specifically, one has a sort of trampoline code that wraps a ref
counted object in an existential ref container (which from an ARC perspective
doesn't imply ownership) and then calls a method on it or passes it off to some
other code.

Because of this requirement, there is a copy/destroy that can not be eliminated
unless we can devirt/inline/eliminate the init_existential_ref box, inline
enough that the low level ARC optimizer can hit it. We shouldn't rely on such
properties if we do not need to.

@gottesmm gottesmm requested a review from atrick March 9, 2020 01:48
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci benchmark

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 9, 2020

Performance: -O

Regression OLD NEW DELTA RATIO
IterateData 795 879 +10.6% 0.90x (?)
 
Improvement OLD NEW DELTA RATIO
StringInterpolationManySmallSegments 10800 8900 -17.6% 1.21x (?)

Code size: -O

Performance: -Osize

Code size: -Osize

Performance: -Onone

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: 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

@swift-ci
Copy link
Contributor

swift-ci commented Mar 9, 2020

Build failed
Swift Test OS X Platform
Git Sha - 530298e8672e82373208dde902b5972adb3f3f3a

@swift-ci
Copy link
Contributor

swift-ci commented Mar 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - 530298e8672e82373208dde902b5972adb3f3f3a

…ranteed and owned.

Otherwise in call frames like the one in the test in this commit get unneeded
ARC traffic. We should never pessimize read only code that doesnt need
side-effects with side-effects if we can avoid it.

I am seeing this a bunch when I look at SIL from projects that use a lot of
protocols. Specifically, one has a sort of trampoline code that wraps a ref
counted object in an existential ref container (which from an ARC perspective
doesn't imply ownership) and then calls a method on it or passes it off to some
other code.

Because of this requirement, there is a copy/destroy that can not be eliminated
unless we can devirt/inline/eliminate the init_existential_ref box, inline
enough that the low level ARC optimizer can hit it. We shouldn't rely on such
properties if we do not need to.
@gottesmm gottesmm force-pushed the pr-20d3a11a596c39f79b461a829ff03722b9755ec9 branch from 530298e to e9896fb Compare March 9, 2020 06:22
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci smoke test and merge

4 similar comments
@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci smoke test and merge

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci smoke test and merge

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci smoke test and merge

@gottesmm
Copy link
Contributor Author

gottesmm commented Mar 9, 2020

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 883d546 into swiftlang:master Mar 9, 2020
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.

Very happy about this.

// class based code where we are propagating around a plus zero version of a
// value and need to wrap the class in an existential wrapper in an intermediate
// frame from usage. In such cases, we have been creating unnecessary ref count
// traffic in code.
Copy link
Contributor

Choose a reason for hiding this comment

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

@gottesmm it's hard to understand this comment because you're explaining a previous implementation. Just explain the key points of the current implementation:

  • it has no net effect on RC
  • it consumes an owned value to produce an owned existential
  • or it "extends" a borrowed value to produce a borrowed existential inside the lifetime of the original value

I'm saying the a forwarding cast "extends" a borrow, while a guaranteed phi (or tuple/struct) "reborrows" the value, unless you have other terms

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 am fine with that.

@gottesmm gottesmm deleted the pr-20d3a11a596c39f79b461a829ff03722b9755ec9 branch July 23, 2021 21:48
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