Compile all your dependencies
What I've noticed some time ago is that if you change the version of Go the libs stay at old version. This causes them to be built on eachgo run
you invoke. And if you use a library which
automates rebuilding the binary on change like reflex () than you may wait long.
List all deps
To list all dependencies your application or library have you can invoke:go list -f '{{.Deps}}' | tr "[" " " | tr "]" " " | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' > deps
(borrowed from from go-nuts)
Rebuild all packages
After that you can call:go install -a $(tr -d '\n' < deps)
Update all packages
Alternative to the above, updates the code:go install -u $(tr -d '\n' < deps)
Speedup
For my code it was from 15 seconds to below 1 second.
Apply to all subpackages in a project
As Craig Furman suggested in a comment (thanks):go list -f '{{.Deps}}' ./... | tr "[" " " | tr "]" " " | \
xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | \
xargs go install -a
Really helpful, this brought compilation time of my project (~10 non-stdlib dependencies) down from 17 seconds back to 1 second! I now can't see a time difference between Go 1.5.1 and 1.4.2.
ReplyDeleteAlso, a modification to apply this recursively to all your sub-packages in a project:
Delete`go list -f '{{.Deps}}' ./... | tr "[" " " | tr "]" " " | xargs go list -f '{{if not .Standard}}{{.ImportPath}}{{end}}' | go install -a`
thanks for this blogpost!
ReplyDeletehttp://kokizzu.blogspot.co.id/2016/06/solution-for-golang-slow-compile.html