g
g copied to clipboard
[FEAT] Reduce binary size
g v0.3.0 takes up 16.7 MiB, it is insane even given that it's statically compiled with -s -w flags.
Comparison with other Go-based apps:
$ g -1 --size
3.8 MiB age.exe
9.4 MiB dnscrypt-proxy.exe
11.8 MiB doggo.exe
6.7 MiB f2.exe
3.0 MiB goawk.exe
Originally posted by @sergeevabc in https://github.com/Equationzhao/g/discussions/172#discussioncomment-13082275
The go size analyzer shows that go-get adds about 770 KB to the binary. Since go-git doesn't offer better performance compared to the git CLI, it's reasonable to remove this dependency.
- [x] remove go-git
The go size analyzer shows that go-get adds about 770 KB to the binary. Since go-git doesn't offer better performance compared to the git CLI, it's reasonable to remove this dependency.
- [x] remove go-git
Compared to the original version with go-git, removing the dependency reduces the binary size by 3.2 MiB on macOS arm64.
after using upx
The go size analyzer shows that go-get adds about 770 KB to the binary. Since go-git doesn't offer better performance compared to the git CLI, it's reasonable to remove this dependency.
- [x] remove go-git
done in #240
I try not to use UPX with programs that require frequent calls, and g is one of those. Why? Because the compressed file starts with a noticeable, and therefore annoying, half-second delay. There must be a way to reduce the size of the exe file by using other people's libraries more precisely and economically.
The Windows x64 binary is now dropped to 8.8MB. There may still be room for further optimization, and I’ll keep an eye on this issue going forward.