6

I have a Go program that uses the Qt wrapper library https://github.com/therecipe/qt. Unfortunately, the build time gets extremely high with it (assuming it's the go part)

go build -i .  // takes about 14 seconds
go run .       // takes about 8 seconds

After running either of the above commands I get the pre-compiled dependencies in my $GOPATH/pkg/linux_amd64/github.com/therecipe/qt as .a files so they are not rebuilding each time.

I've tried to use ccache and Gold linker /usr/bin/ld.gold as described in https://github.com/therecipe/qt/wiki/Faster-builds-(Linux) but it didn't improve anything. Also this Qt wrapper ships with its own build tool qtdeploy which I tried but it is roughly the same build time.

System I'm running on:

go version go1.14.4 linux/amd64
Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
16GB Ram

Would anyone know if it's possible to improve the build time at least a bit?

EDIT:

Running go build -x . shows that the biggest time consumer is the following command

~/.go/pkg/tool/linux_amd64/link -o $WORK/b001/exe/a.out -importcfg $WORK/b001/importcfg.link -buildmode=exe -buildid=k8lYa6JYqRdCY9Gyt0jX/16myMybByG5X6rOfaRpS/WHdW2kCTfMCZs2I4x9WE/k8lYa6JYqRdCY9Gyt0jX -extld=g++ ~/.cache/go-build/b5/b5e47b7f77c2df06ba69937dc8b1399b1289b7c90d2e08b3341fdf13e119c860-d
Neo
  • 208
  • 2
  • 5
wasp256
  • 5,943
  • 12
  • 72
  • 119
  • 3
    Can you run `go build -x` and inspect the build log? `-x` makes `go build` write out every step it takes to produce the executable image. – kostix Aug 05 '20 at 10:54
  • @kostix I updated the question with the command that consumes the most time from `go build -x` – wasp256 Aug 05 '20 at 11:30
  • try `CGO_ENABLED=0 go build . ` – kozmo Aug 05 '20 at 13:17
  • `-extld=g++` hints at that it's gcc's linker which is slow. I have no immediate idea on how to time it (except for wrapping `g++` with a custom script in the `PATH` which would somehow instrument a call to the real `g++` to help to find out where it's spending). – kostix Aug 05 '20 at 16:02
  • @kozmo, how disabling `cgo` is supposed to work when the program explicitly uses C or C++ library code? – kostix Aug 05 '20 at 16:02
  • Have you tried running perf to analyze what g++ is doing? – Gustavo Kawamoto Aug 14 '20 at 12:01
  • https://stackoverflow.com/a/47714438/8030651 – kozmo Aug 15 '20 at 07:34
  • @kozmo Building with teh `CGO_ENABLED=0` flag will result in an output (without doing any compiling): `package test imports github.com/therecipe/qt/core: build constraints exclude all Go files in /home/dan/Golang/Programs/src/github.com/therecipe/qt/core`. As @kostix already pointed out, how would that even work if it uses C/C++ library code? – wasp256 Aug 16 '20 at 04:19
  • @GustavoKawamoto how would I analyze what g++ is actually doing? – wasp256 Aug 16 '20 at 04:20
  • `perf` is a linux tool for profiling, you can find it in the `linux-tools` package in Ubuntu. You can use it by recording the events while running your command (`perf record`) or see in real time (`perf top`), both using root. The perf tool will profile the calls and give you an idea where your application is hogging. For more info, see https://perf.wiki.kernel.org/index.php/Tutorial – Gustavo Kawamoto Aug 17 '20 at 10:59

0 Answers0