如何提高Golang的编译速度?

huangapple go评论84阅读模式
英文:

How to improve Golang compilation speed?

问题

我正在尝试找到一种加快 Go 程序编译速度的方法。目前编译时间大约为30秒,这使得项目的工作速度变慢。

当我运行 go build -v 时,我发现大部分时间都花在编译 go-sqlite3 上(它链接到 C 语言的 sqlite 库)。然而,由于这个库从不改变,我想知道是否有可能阻止构建工具每次都重新编译它?

英文:

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?

答案1

得分: 46

尝试运行go install -a github.com/mattn/go-sqlite3命令,它会将编译针对Go 1.3的包安装到你的$GOPATH中。

目前,你可能在$GOPATH/pkg/目录下安装了一个较旧的版本,因此每次构建时Go都会重新编译它。

英文:

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.

答案2

得分: 3

这可能是因为您升级到了go 1.3版本。

我不得不删除$GOPATH/pkg目录以摆脱旧的(不兼容的)二进制文件,
然后它就能够再次缓存编译结果了。

英文:

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

答案3

得分: 0

在Go 1.10中,不需要运行go install等命令,只需使用go build即可。新版本使用构建缓存来确定哪些包需要重新编译。

请查看:https://tip.golang.org/doc/go1.10

英文:

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

huangapple
  • 本文由 发表于 2014年7月7日 08:32:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/24601619.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定