Is it normal for a tiny Go HTTP service to build a 14MB binary Tooling
Four endpoints, one Postgres query, no fancy dependencies as far as I know. go build gives me 14MB, which surprised me because everyone talks about Go producing small self-contained binaries. Coming from Python where the file is 400 lines and that's the whole thing. Is this expected or did I import something enormous by accident?
@easy_pace_ellis · 11mo ago · 3 replies
Expected. You're shipping the whole runtime, the garbage collector, and everything statically linked, so a hello-world is already about 2MB before you write any code. 14MB for a real service with a database driver is normal.
Easy trim:
go build -ldflags="-s -w"drops the symbol table and DWARF info, usually 25-30% off. You lose readable stack traces in some tooling, which I'd think about before doing it in production.And the comparison that matters is not against a 400-line .py file, it's against the Python interpreter plus site-packages you have to install on the target box.
Reply
Report
@committee_kim · 11mo ago
Before you strip anything, run
go tool nm -size -sort size yourbinary | head -40. It tells you what actually took the space, and about half the time it's one dependency you forgot you pulled in.go version -m yourbinarylists the module versions baked in too.Reply
Report
@flashcard_fen · 11mo ago
Fair, when I put it that way my "small" Python service is a 900MB container image.
Reply
Report