Skip to content
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

build: selectively convert modules to static linking in CMake #8268

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

compnerd
Copy link
Member

Convert a few libraries to static linking. This results in a net size
reduction for the toolchain as a whole while also reducing the
distributed DLLs.

PackageModelSyntax Conversion:

Before:
 6621696 sourcekit-lsp.exe
 3844608 Commands.dll
  144384 PackageModelSyntax.dll
 -------
 10610688

After:
  6712320 sourcekit-lsp.exe
  3950592 Commands.dll
 --------
 10662912

Savings: 52,224 bytes

SwiftSDKCommand Conversion:

Before:
  23552 swift-sdk.exe
 267776 SwiftSDKCommand.dll
 ------
 291328

After:
 265728 swift-sdk.exe

Savings: 25,600 bytes

CoreCommands Conversion:

Before:
 3844608 Commands.dll
 1065472 CoreCommands.dll
  265728 swift-sdk.exe
 -------
 5175808

After:
 4202496 Commands.dll
  649728 swift-sdk.exe
 -------
 4852224

Savings: 323,584 bytes

DriverSupport Conversion:

Before:
  945152 Build.dll
 4202496 Commands.dll
   49152 DriverSupport.dll
  649728 swift-sdk.exe
 -------
 5846528

After:
  958976 Build.dll
 4217856 Commands.dll
  669184 swift-sdk.exe
 -------
 5846016

Savings: 512 bytes

Net Savings: 401,920 bytes

@compnerd
Copy link
Member Author

Please test with following PRs:
swiftlang/swift-installer-scripts#373

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

@swift-ci please smoke test Linux platform

@compnerd
Copy link
Member Author

@swift-ci please smoke test macOS platform

@compnerd
Copy link
Member Author

@swift-ci please test macOS platform

@compnerd
Copy link
Member Author

@swift-ci please test Linux platform

@compnerd
Copy link
Member Author

compnerd commented Feb 3, 2025

Please test with following PRs:
swiftlang/swift-installer-scripts#373

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented Feb 3, 2025

Please test with following PRs:
swiftlang/swift-installer-scripts#373

@swift-ci please test Windows platform

@dschaefer2
Copy link
Member

Trying to grapple with the numbers. Don't the PackageModelSyntax Conversion numbers show things are bigger?

Aside from that, I've been kinda confused by this whole exercises. Doesn't making things static libraries mean the code is copied into all the executables and DLLs that consume them, making the overall thing bigger? I'm trying to understand why it's smaller. Is it dead code that isn't used by anyone?

@dschaefer2
Copy link
Member

Or is it test code that ends up in the DLL but not used by any of the exe's, only the tests?

@compnerd
Copy link
Member Author

compnerd commented Feb 7, 2025

Trying to grapple with the numbers. Don't the PackageModelSyntax Conversion numbers show things are bigger?

Yes! The first one alone would increase the size. However, as more collapsed later, it becomes smaller.

Aside from that, I've been kinda confused by this whole exercises. Doesn't making things static libraries mean the code is copied into all the executables and DLLs that consume them, making the overall thing bigger? I'm trying to understand why it's smaller. Is it dead code that isn't used by anyone?

Yes, this is very much confusing. The code is copied. However, with static linking, we are able to perform DCE. Because the code is not uniformly used, the combination of that and all the indirection sometimes ends up with a smaller binary. I was trying to go further with this, but that seemed to always increase the size rather than decrease.

It would be nice to split up the library code such that we can dynamically link a single library for SourceKit-LSP so that we do not increase the binary size.

This adjusts the dependency graph to match the reality of the sources.
Convert a few libraries to static linking. This results in a net size
reduction for the toolchain as a whole while also reducing the
distributed DLLs.

PackageModelSyntax Conversion:
~~~
Before:
 6621696 sourcekit-lsp.exe
 3844608 Commands.dll
  144384 PackageModelSyntax.dll
 -------
10610688

After:
 6712320 sourcekit-lsp.exe
 3950592 Commands.dll
--------
10662912
~~~

Savings: 52,224 bytes

SwiftSDKCommand Conversion:
~~~
Before:
 23552 swift-sdk.exe
267776 SwiftSDKCommand.dll
------
291328

After:
265728 swift-sdk.exe
~~~

Savings: 25,600 bytes

CoreCommands Conversion:
~~~
Before:
3844608 Commands.dll
1065472 CoreCommands.dll
 265728 swift-sdk.exe
-------
5175808

After:
4202496 Commands.dll
 649728 swift-sdk.exe
-------
4852224
~~~

Savings: 323,584 bytes

DriverSupport Conversion:
~~~
Before:
 945152 Build.dll
4202496 Commands.dll
  49152 DriverSupport.dll
 649728 swift-sdk.exe
-------
5846528

After:
 958976 Build.dll
4217856 Commands.dll
 669184 swift-sdk.exe
-------
5846016
~~~

Savings: 512 bytes

Net Savings: 401,920 bytes
@compnerd
Copy link
Member Author

@swift-ci please test

@compnerd
Copy link
Member Author

@swift-ci please test Windows platform

@compnerd
Copy link
Member Author

Please test with following PRs:
swiftlang/swift-installer-scripts#373

@swift-ci please test Windows platform

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.

4 participants