英文:
"go build" became very slow after installing a new version of Go
问题
从Go 1.2.1升级到1.3(Windows 7 64位)后,“go build”执行时间从大约4秒增加到超过45秒。除了Go版本更新外,没有进行其他更改。关闭病毒扫描似乎没有效果。有什么线索吗?
英文:
After upgrading from Go 1.2.1 to 1.3 (Windows 7 64 bit) "go build" execution time has increased from around 4 to over 45 seconds. There were no other changes except the go version update. Switching off the virus scanner seems to have no effect. Any clues?
答案1
得分: 58
你可能有一些依赖项每次都在重新编译。尝试使用go install -a mypackage
命令重新构建所有依赖项。
删除$GOPATH/pkg
目录也有助于确保你没有旧的目标文件残留。
使用-x
标志进行构建可以显示工具链是否找到了不兼容的版本。
英文:
You probably have dependencies that are being recompiled each time. Try go install -a mypackage
to rebuild all dependencies.
Removing $GOPATH/pkg
also helps to ensure you don't have old object files around.
Building with the -x
flag will show you if the toolchain is finding incompatible versions.
答案2
得分: 26
我有完全相同的问题,运行以下命令可以解决:
go get -u -v github.com/mattn/go-sqlite3
另一个提示:http://kokizzu.blogspot.co.id/2016/06/solution-for-golang-slow-compile.html
英文:
I have the exact same problem, running this command solves it:
go get -u -v github.com/mattn/go-sqlite3
Another tip: http://kokizzu.blogspot.co.id/2016/06/solution-for-golang-slow-compile.html
答案3
得分: 19
使用go1.6版本,只需运行go build -i
命令即可。
它会编译所有的依赖项,并将它们存储在$GOPATH/pkg/*/*
目录下的__.a__文件中。
之后,当你运行go run main.go
时,一切都会更快。
真正棒的是,如果你使用了供应商依赖(例如:项目中的vendor文件夹),依赖项会在$GOPATH/pkg/**/yourproject/vendor/**
目录中正确构建。
因此,你不需要执行go get install/get/whatever
命令,并且不会混合使用供应商依赖和全局依赖。
我怀疑在更新依赖项后(例如使用glide update或类似的命令),你需要重新构建__.a__文件,但我还没有测试过。
英文:
Using go1.6,
Simply run go build -i
.
It will compile all the dependencies and store them at $GOPATH/pkg/*/*
as .a files.
Later when you run go run main.go
, everything is much faster.
What s really great is that if you use vendored dependencies (IE: a vendor folder in your project), deps are built appropriately within $GOPATH/pkg/**/yourproject/vendor/**
So you don t have to go get install/get/whatever
and have a mix of vendor / global dependencies.
I suspect you got to re-build .a files after deps update (glide update or smthg like this), but i did not test that yet.
答案4
得分: 6
在Go 1.10之后,你只需要输入go build
命令。不需要输入go build -i
命令。
来自Go 1.10草案文档,在这里。
构建和安装
现在,go build命令仅根据源文件的内容、指定的构建标志和编译包中存储的元数据来检测过时的包。不再考虑修改时间。不再需要根据修改时间来添加 -a 标志以强制重新构建,因为修改时间可能因某种原因(例如构建标志的更改)而具有误导性:现在构建总是能够检测到必须重新构建的包。(如果你观察到不同情况,请报告一个bug。)
...
go build命令现在维护一个最近构建的包的缓存,与$GOROOT/pkg或$GOPATH/pkg中安装的包分开。 缓存的效果应该是加快构建速度,不需要显式安装包或在不同的源代码副本之间切换时(例如在版本控制系统中来回切换不同的分支)使用 -i 标志以提速的旧建议不再需要:构建速度不带 -i 也同样快。有关更多详细信息,请参阅go help cache。
英文:
After Go 1.10, you'd just need to type go build
. You'd not need to type: go build -i
.
> From the draft Go 1.10 document, here.
> ---
> Build & Install
> The go build command now detects out-of-date packages purely based on the content of source files, specified build flags, and metadata stored in the compiled packages. Modification times are no longer consulted or relevant. The old advice to add -a to force a rebuild in cases where the modification times were misleading for one reason or another (for example, changes in build flags) is no longer necessary: builds now always detect when packages must be rebuilt. (If you observe otherwise, please file a bug.)
> ...
> The go build command now maintains a cache of recently built packages, separate from the installed packages in $GOROOT/pkg or $GOPATH/pkg. The effect of the cache should be to speed builds that do not explicitly install packages or when switching between different copies of source code (for example, when changing back and forth between different branches in a version control system). The old advice to add the -i flag for speed, as in go build -i or go test -i, is no longer necessary: builds run just as fast without -i. For more details, see go help cache.
答案5
得分: 3
我刚刚遇到了同样的问题——从1.4版本升级到1.5版本。似乎旧版本在某种程度上不兼容,或者每次都会重新构建,正如go build -x
所显示的那样。执行go get -v
会使所有包失效或重新获取它们,我不太确定,而且go build -x
的输出要少得多。
英文:
I just experienced the same problem - updating from 1.4 to 1.5. It seems that the olds versions are somehow incompatible or are being rebuild every time as go build -x
shows. Executing go get -v
invalidates all packages or refetches them, I am not quite sure and go build -x
shows quite less output.
答案6
得分: 1
你可以按照以下方式构建sqlite3:
cd ./vendor/github.com/mattn/go-sqlite3/
go install
之后,你的项目将会构建得更快。
英文:
You can build sqlite3 like this:
cd ./vendor/github.com/mattn/go-sqlite3/
go install
After that your project will b built much faster.
答案7
得分: -3
如果你按照其他人说的尝试了但仍然不起作用,我建议删除$GOPATH
目录,例如:
sudo rm -rf $GOPATH
cd yourproject
go get -d
go get -u -v github.com/mattn/go-sqlite3
英文:
If you try as all other said but still not work, I suggest removing the directory of $GOPATH
such as :
sudo rm -rf $GOPATH
cd yourproject
go get -d
go get -u -v github.com/mattn/go-sqlite3
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论