Swift and the Reduced Binary Size

Marat Saytakov
1 min readJun 19, 2017

Previously I wrote about a command line tool architecture. There was a program to add events to macOS Calendar. After all, a final binary file size was 10 MB in Debug build configuration and 6 MB in Release.

I’m pretty sure it isn’t a good world where this type of programs takes that much millions of bytes. 640 KB ought to be enough for anybody.

Reducing binary size isn’t a new problem, but Swift binaries takes its runtime embedded though. So before we’ve got ABI stability, I started research how to deal with it. The research quickly ended up after the first question to my friend Aleksandr Tuchkov. He briefly answered: UPX.

UPX

I never heard about it. It is a truly magic tool:

  • final binary executable reduced to from 6.5 MB to 1.8 MB
  • doesn’t need any dependencies or libraries to “unpack”
  • almost no decompressing overhead

Nifty, eh? Install via Homebrew: brew install upx. Usage: upx myapp. It will replace archived project’s executable with a reduced one.

Via Fastlane

I guess Fastlane isn’t designed to build command line programs. But it would be awesome to delegate testing, building and packing everything automatically to someone else. I found out there is no fastlane action for UPX, but we can run it in this way via Ruby:

Final reduced executable will be in the project folder. UPX plugin for fastlane is here and coming soon: fastlane-plugin-upx.

--

--

Responses (2)