You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I always thought Go only imports the libraries which are used, but looking at the thread it seems it is otherwise. TIL.
Current binary size (plain go build and no optimisations) on my machine is 27 MB. I will check with https://github.com/knadh/koanf and report here.
koanf fits well as a replacement, we need support of both JSON file and env variables. Another alternative is https://github.com/ilyakaznacheev/cleanenv but I don't have any preference of one over another.
(The entire reported size by go tool is being shown as ~20MB, I am guessing it strips off the debug symbols)
So, one way to reduce the size would be to strip debug and symbol table info:
go build -ldflags="-s -w"
This reduces the size to 20MB from 27MB and this does not affect stack trace / panic info.
I found one more trick, by using upx the size now reduced to tiny 5 MB. One downside people mentioned that it can affect startup time since all of it is decompressed at the time of executing, but I did not notice any difference.
(all of this run on my intel mac running monterey, with go 1.20)
We use Viper for really simple local settings file, but the amount of dependencies it pulls is very large:
spf13/viper#707
Let's consider using something else instead of Viper to reduce the number of dependencies.
The text was updated successfully, but these errors were encountered: