“go build” became very slow after installing a new version of Go

前端 未结 7 887
清酒与你
清酒与你 2021-01-31 08:35

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 ver

相关标签:
7条回答
  • 2021-01-31 08:50

    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.

    0 讨论(0)
  • 2021-01-31 08:52

    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

    0 讨论(0)
  • 2021-01-31 08:54

    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
    
    0 讨论(0)
  • 2021-01-31 08:56

    You can build sqlite3 like this:

    cd ./vendor/github.com/mattn/go-sqlite3/
    go install
    

    After that your project will b built much faster.

    0 讨论(0)
  • 2021-01-31 09:05

    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.

    0 讨论(0)
  • 2021-01-31 09:06

    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.

    0 讨论(0)
提交回复
热议问题