4

Let's say you import a Swift package from which you only need a tiny piece (for example a single method from the Swift Algorithms package)

It seems the linker doesn't optimize away all the other methods - for a simple example project only using chunks(ofCount:) from the Swift Algorithms package the binary size grew from 193 KB to 3,9 MB. So it seems getting only a tiny piece of a large package is a bad idea if you care about app binary size.

Is there a better way to reduce the resulting app binary size besides removing the Swift package and copying the actually needed source files to your own project?

7
  • 1
    What did your experimentation suggest might be the answer?
    – matt
    Jun 29, 2021 at 6:13
  • It seems not to optimize -> updated the question.
    – Ralf Ebert
    Jun 29, 2021 at 6:17
  • No, you cannot use only a part of a library. How would work? A library is a file and you cannot just include a part of that file in your binary.
    – Sulthan
    Jun 29, 2021 at 6:26
  • Instead of import a full package, create an empty swift file, and copy just the needed codes from the library.
    – Dris
    Jun 29, 2021 at 9:52
  • yes, copying the source file obviously works, and still, I am looking for a better way. In theory the linker could only link symbols that are needed or optimize away symbols not needed at all.
    – Ralf Ebert
    Jun 29, 2021 at 11:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.