cmd/go: list -compiled -find ignores cgo caching
heschi opened this issue · 2 comments
What version of Go are you using (go version)?
$ go version go version devel +90dca98d33 Thu Dec 20 22:11:45 2018 +0000 linux/amd64
Does this issue reproduce with the latest release?
Think so.
What did you do?
time ~/go/bin/go list -e -json -compiled -x net >/dev/null
~/go/bin/go list -e -json -compiled -x net > /dev/null 0.14s user 0.07s system 216% cpu 0.094 total
time ~/go/bin/go list -e -json -compiled -find net >/dev/null
~/go/bin/go list -e -json -compiled -find net > /dev/null 0.45s user 0.27s system 106% cpu 0.674 total
What did you expect to see?
I expected -find to make it faster or at least not slower.
What did you see instead?
It made it slower, because it's rerunning cgo compilation with -find for some reason.
When "go list" is invoked with -find, it clears the list of imports for each package matched on the command line. This affects action IDs, since they incorporate dependencies' action IDs. Consequently, the build triggered by -compiled won't find sources cached by "go build".
I don't think there's any reason we shouldn't use sources produced by previous runs of "go list -find -compiled" though. cgo-generated sources are not affected by imported packages, as far as I know.
Change https://golang.org/cl/155481 mentions this issue: cmd/go: use cached source files in "go list -find -compiled"