31

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?

laurent
  • 88,262
  • 77
  • 290
  • 428
  • 2
    Potential duplicate of: http://stackoverflow.com/questions/24341654/go-build-became-very-slow-after-installing-a-new-version-of-go – dyoo Jul 08 '14 at 02:17
  • The compilation speed will improve with Go 1.10 (Q1 2018): https://stackoverflow.com/a/47109826/6309 – VonC Nov 04 '17 at 10:50

3 Answers3

46

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.

elithrar
  • 23,364
  • 10
  • 85
  • 104
3

This is likely due to you upgrading to go 1.3

I had to remove $GOPATH/pkg to get rid of old (incompatible) binaries and then it was able to cache compilation results again

David Budworth
  • 11,248
  • 1
  • 36
  • 45
0

In Go 1.10 no need to run go install etc. Just use go build. The new version uses a build cache to determine which packages need to be re-compiled.

Check out: https://tip.golang.org/doc/go1.10

Inanc Gumus
  • 25,195
  • 9
  • 85
  • 101