I'm trying to find a way to make the compilation of a Go program faster. It is currently about 30 seconds, which makes it slow to work with the project.
When I run go build -v
, I see that most of the time is spent compiling go-sqlite3 (which links to the C sqlite lib). However, since this lib never changes, I'm wondering if it's possible to prevent the build tool from recompiling this every time?
Go is very simple, lean, and minimalist: For example, there are only 25 keywords in Golang. Being simple and easy to learn was also one of the design choices while creating Golang. There are very little clutter and complexities. However, this also helped in faster compilation time.
Go is a really fast language. Because Go is compiled to machine code, it will naturally outperform languages that are interpreted or have virtual runtimes. Go programs also compile extremely fast, and the resulting binary is very small. Our API compiles in seconds and produces an executable file that is 11.5 MB.
Overall, Golang beats C++ hands down when it comes to coding speed.
One of the main things that make Go compile fast is its dependency management. To say simply, Go imports only those packages that are directly required for the program other than C/C++ compilers. There are also no templates which amounts to less preprocessing overhead.
Try go install -a github.com/mattn/go-sqlite3
which will install the compiled-against-Go-1.3 package into your $GOPATH.
Right now, you likely have an older version installed under $GOPATH/pkg/
and therefore Go is recompiling it for every build.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With