Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to improve Golang compilation speed?

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?

like image 886
laurent Avatar asked Jul 07 '14 00:07

laurent


People also ask

How is Golang compiler so fast?

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.

Does Go compiles very quickly?

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.

Is Go faster than C++?

Overall, Golang beats C++ hands down when it comes to coding speed.

Why Golang is fast?

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.


Video Answer


1 Answers

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.

like image 157
elithrar Avatar answered Sep 21 '22 23:09

elithrar