Consider upx for squashing binary size #306

Open
opened 2022-03-31 21:04:09 +00:00 by decentral1se · 2 comments
Owner

Via https://github.com/goreleaser/goreleaser/pull/148.

abra binaries go from 19M to 7M when run under upx.

Start-up time is affected, it is slower. Is it noticeable tho?

➜ make build
➜ du -sh abra
19M	abra               
➜ time ./abra -v
abra version dev-f09ca6e
./abra -v  0.05s user 0.01s system 123% cpu 0.051 total
➜ upx abra 
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2018
UPX 3.95        Markus Oberhumer, Laszlo Molnar & John Reiser   Aug 26th 2018

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
  18944000 ->   7234052   38.19%   linux/amd64   abra                          

Packed 1 file.
➜ du -sh abra
7.0M	abra               
➜ time ./abra -v
abra version dev-f09ca6e   
./abra -v  0.18s user 0.01s system 102% cpu 0.185 total
Via https://github.com/goreleaser/goreleaser/pull/148. `abra` binaries go from 19M to 7M when run under `upx`. Start-up time is affected, it is slower. Is it noticeable tho? ``` ➜ make build ➜ du -sh abra 19M abra ➜ time ./abra -v abra version dev-f09ca6e ./abra -v 0.05s user 0.01s system 123% cpu 0.051 total ➜ upx abra Ultimate Packer for eXecutables Copyright (C) 1996 - 2018 UPX 3.95 Markus Oberhumer, Laszlo Molnar & John Reiser Aug 26th 2018 File size Ratio Format Name -------------------- ------ ----------- ----------- 18944000 -> 7234052 38.19% linux/amd64 abra Packed 1 file. ➜ du -sh abra 7.0M abra ➜ time ./abra -v abra version dev-f09ca6e ./abra -v 0.18s user 0.01s system 102% cpu 0.185 total ```
decentral1se added the
enhancement
label 2022-03-31 21:04:09 +00:00
Author
Owner

With:

diff --git a/.drone.yml b/.drone.yml
index 46c6c90..9d0bdd0 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -45,7 +45,7 @@ steps:
       event: tag
 
   - name: release
-    image: golang:1.18
+    image: devopsworks/golang-upx:1.18
     environment:
       GITEA_TOKEN:
         from_secret: goreleaser_gitea_token
diff --git a/.goreleaser.yml b/.goreleaser.yml
index 5c7761c..7419e34 100644
--- a/.goreleaser.yml
+++ b/.goreleaser.yml
@@ -26,6 +26,9 @@ builds:
     ldflags:
       - "-X 'main.Commit={{ .Commit }}'"
       - "-X 'main.Version={{ .Version }}'"
+    hooks:
+      post:
+        - ./scripts/release/upx.sh
 archives:
   - replacements:
       386: i386

And:

#!/bin/bash

set -ex

upx ./dist/abra_*/abra

I can get it to work, but I think it will affect the checksum generation.

Leaving off for now.

With: ```diff diff --git a/.drone.yml b/.drone.yml index 46c6c90..9d0bdd0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -45,7 +45,7 @@ steps: event: tag - name: release - image: golang:1.18 + image: devopsworks/golang-upx:1.18 environment: GITEA_TOKEN: from_secret: goreleaser_gitea_token diff --git a/.goreleaser.yml b/.goreleaser.yml index 5c7761c..7419e34 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -26,6 +26,9 @@ builds: ldflags: - "-X 'main.Commit={{ .Commit }}'" - "-X 'main.Version={{ .Version }}'" + hooks: + post: + - ./scripts/release/upx.sh archives: - replacements: 386: i386 ``` And: ```bash #!/bin/bash set -ex upx ./dist/abra_*/abra ``` I can get it to work, but I think it will affect the checksum generation. Leaving off for now.
Author
Owner

Checked again, abra from 20M -> 5.5M and kadabra to 4.6M! Really need to get around to this, especially for kadabra where startup times won't be really noticed at all due to being a server-side component.

Checked again, `abra` from 20M -> 5.5M and `kadabra` to 4.6M! Really need to get around to this, especially for `kadabra` where startup times won't be really noticed at all due to being a server-side component.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: coop-cloud/organising#306
No description provided.