logoalt Hacker News

maccardyesterday at 4:12 PM1 replyview on HN

What does it look like if you pass -ldflags=“-s -w”?


Replies

guessmynameyesterday at 10:28 PM

With Go v1.26.1

  package main
  import "fmt"
  func main() {
    fmt.Printf("Hello World!\n")
  }
Binary sizes:

• 2581616B (2.5MB) → 1714560B (1.6MB) (with -ldflags="-s -w")

• 1531920B (1.5MB) → 753680B (0.7MB) (with upx --force-macos)

That said, a trivial “Hello World!” isn’t a meaningful benchmark. If you’re going to play that game, you might as well swap `fmt.Printf` for `fmt.Println`, or even `println` to avoid the import statement entirely. At that point, you’re no longer comparing anything interesting, the binaries end up roughly the same size anyway.

show 1 reply