2016-06-05

Real Reason to use newer Go 1.5+: Cross Compile

As you already know, that compiling in Golang becomes slower since 1.5+, then why we must use the newer? there's no incompatible syntax changes right? See the graph below for the compile duration ratio:


There's some you must consider when using older Go version (<1.4.3):
  1. Broken libraries, some libraries (such as fasthttp) doesn't support older version of Go (<1.5), because there are changes on standard libraries, for example there's no bytes.LastIndexByte, bufio.Reader.Discard,  time.Time.AppendFormat, etc on older version of go standard library)
  2. Slower GC (see Go 1.6 latest low latency garbage collector, it's even less than 21ms)
  3. Bigger binary produced (but see goupx)
  4. Slower runtime performance (but it's already fast compared to another language)
  5. No Vendoring (see no more dependency hell)
  6. And lastly, no Cross Compiling!
Did you know that since Go 1.5 you can build other platform's binary?

$ go build
-rwxr-xr-x   1 asd  staff  11261296 Jun  5 19:41 PUPS
PUPS: Mach-O 64-bit executable x86_64

$ env GOOS=linux GOARCH=amd64 go build
-rwxr-xr-x   1 asd  staff  9232191 Jun  5 19:42 PUPS
PUPS: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, not stripped

$ env GOOS=windows GOARCH=386 go build
-rwxr-xr-x   1 asd  staff  8048640 Jun  5 19:42 PUPS.exe
PUPS.exe: PE32 executable for MS Windows (console) Intel 80386 32-bit

This feature is really useful especially when your server is Linux, but you develop in Mac :3
Or when you want to create a cross-platform games/apps.