Skip to content

Remove dead bridging calls for dead parameters #19797

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 2 commits into from
Oct 10, 2018

Conversation

eeckstein
Copy link
Contributor

This PR consists of 2 changes:

  • lazily emit shared witness tables: This avoids emitting synthesized witness tables if they are not needed.

  • mark all _unconditionallyBridgeFromObjectiveC functions as @_effects(readonly): Read-only lets the optimizer remove such a call if the result is not used.
    Note that "readonly" means: no observable write operations. It's okay to allocate and initialize new objects.

rdar://problem/44944094

@eeckstein
Copy link
Contributor Author

@swift-ci test

@eeckstein
Copy link
Contributor Author

@swift-ci benchmark

@swift-ci
Copy link
Contributor

swift-ci commented Oct 9, 2018

Build comment file:

Performance: -O

TEST OLD NEW DELTA RATIO
Improvement
NSStringConversion 717 0 -100.0% 717001.00x

Code size: -O

TEST OLD NEW DELTA RATIO
Improvement
NSStringConversion.o 873 793 -9.2% 1.10x

Performance: -Osize

TEST OLD NEW DELTA RATIO
Regression
StringWalk 1699 2008 +18.2% 0.85x
Improvement
NSStringConversion 732 0 -100.0% 732001.00x

Code size: -Osize

TEST OLD NEW DELTA RATIO
Improvement
NSStringConversion.o 938 858 -8.5% 1.09x

Code size: Swift libraries

TEST OLD NEW DELTA RATIO
Improvement
libswiftCryptoTokenKit.dylib 28672 24576 -14.3% 1.17x
libswiftNaturalLanguage.dylib 45056 40960 -9.1% 1.10x
libswiftNetwork.dylib 172032 163840 -4.8% 1.05x
libswiftXCTest.dylib 86016 81920 -4.8% 1.05x
libswiftAppKit.dylib 86016 81920 -4.8% 1.05x
libswiftCloudKit.dylib 106496 102400 -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 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

@aroben
Copy link

aroben commented Oct 9, 2018

Ah, nice!

Is there a way to make @_effects(readonly) automatic in this case, or to otherwise ensure that it is applied to any new _unconditionallyBridgeFromObjectiveC functions that may get added in the future? It'd be a shame for some new datatype to lose out on this optimization just because the annotation was overlooked.

@eeckstein
Copy link
Contributor Author

Yes, the compiler could enforce this based on the annotation on the protocol requirement.
I created https://bugs.swift.org/browse/SR-8953 for this.

@@ -356,6 +356,7 @@ extension DispatchData {
return true
}

@_effects(readonly)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bad indent here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

interesting. This file has tab indents.
I'll fix it.


// REQUIRES: objc_interop

// Check if the optimizer can remove dead briding calls.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also CHECK-NOT that the witness table was not emitted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test check the SIL. And in SIL the witness tables do get emitted.
For the IRGen part, I put in a CHECK-NOT in test/IRGen/objc_ns_enum.swift

Copy link
Contributor

@phausler phausler left a comment

Choose a reason for hiding this comment

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

from the Foundation overlay this looks fine to me

@phausler
Copy link
Contributor

one quick question however, does this apply to linux bridging as well?

This avoids emitting synthesized witness tables if they are not needed.
…readonly)

This enables removal of those bridging calls for dead parameters. Read-only lets the optimizer remove such a call if the result is not used.
Note that "readonly" means: no observable write operations. It's okay to allocate and initialize new objects.

rdar://problem/44944094
@eeckstein eeckstein force-pushed the remove-dead-bridging-calls branch from 0a87574 to 6e6aae8 Compare October 10, 2018 15:27
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

1 similar comment
@eeckstein
Copy link
Contributor Author

@swift-ci smoke test and merge

@eeckstein
Copy link
Contributor Author

@phausler good point. Yes, it would make sense to add the annotations in swift-corelibs-foundation as well.

@aroben
Copy link

aroben commented Oct 10, 2018

The benchmark output suggests NSStringConversion isn't doing any work anymore. Do we need to modify that test so that it actually performs the conversions? Or maybe there's some other test that covers that, and thus it's a good thing to have this test indicate that the work is skipped when the stores are dead?

@eeckstein
Copy link
Contributor Author

I'll fix the benchmark in a follow-up PR

@swift-ci swift-ci merged commit b507fa2 into swiftlang:master Oct 10, 2018
@eeckstein eeckstein deleted the remove-dead-bridging-calls branch October 10, 2018 16:34
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.

5 participants