Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Viper to something else? #489

Open
penberg opened this issue Jun 21, 2023 · 2 comments
Open

Switch from Viper to something else? #489

penberg opened this issue Jun 21, 2023 · 2 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@penberg
Copy link
Contributor

penberg commented Jun 21, 2023

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.

@penberg penberg added enhancement New feature or request question Further information is requested labels Jun 21, 2023
@avinassh
Copy link
Member

avinassh commented Jul 3, 2023

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.

@avinassh
Copy link
Member

avinassh commented Jul 4, 2023

I removed viper entirely, it didn't make significant difference in the binary size (26MB).

Go has tooling to analyse the binary size, here are the top five external dependencies by size:

$ go tool nm -sort size -size turso
...
github.com/rivo/uniseg
github.com/libsql/sqlite-antlr4-parser/sqliteparser
github.com/chiselstrike/iku-turso-cli/internal/tetris
github.com/gdamore/tcell
github.com/mattn/go-sqlite3

I used a visualiser and here is the svg:

viz

binsize

(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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants