Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: go list without flags calculates deps/imports #27479

Closed
chlunde opened this issue Sep 3, 2018 · 3 comments
Closed

cmd/go: go list without flags calculates deps/imports #27479

chlunde opened this issue Sep 3, 2018 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Milestone

Comments

@chlunde
Copy link
Contributor

chlunde commented Sep 3, 2018

What version of Go are you using (go version)?

go version go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/chlunde/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/chlunde/go"
GOPROXY=""
GORACE=""
GOROOT="/home/chlunde/opt/go"
GOTMPDIR=""
GOTOOLDIR="/home/chlunde/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/chlunde/sample/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build180931290=/tmp/go-build -gno-record-gcc-switches"

What did you do?

cd go/src/k8s.io/client-go
 ~/.../k8s.io/client-go$ time (for a in $(seq 10); do go list  ./...; done) | md5sum -
a1c615c3eb59b2af6e60274312bb4319  -

real	0m3.271s
user	0m3.397s
sys	0m0.745s
 ~/.../k8s.io/client-go$ time (for a in $(seq 10); do go list -find ./...; done) | md5sum -
a1c615c3eb59b2af6e60274312bb4319  -

real	0m1.437s
user	0m1.209s
sys	0m0.452s

What did you expect to see?

go list with just package names should be pretty fast

What did you see instead?

go list parses much of the source code even when -json, -f or -deps is not set, and is often 2-5x faster with -find.

Should -find be set automatically when no other advanced flags are set?

diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go
index f3cb4e47ec..fd9c2d2980 100644
--- a/src/cmd/go/internal/list/list.go
+++ b/src/cmd/go/internal/list/list.go
@@ -311,6 +311,11 @@ func runList(cmd *base.Command, args []string) {
 	out := newTrackingWriter(os.Stdout)
 	defer out.w.Flush()
 
+	// Ignore imports if they do not affect the output
+	if *listFmt == "" && !*listDeps && !*listTest && !*listM && !*listJson {
+		*listFind = true
+	}
+
 	if *listFmt == "" {
 		if *listM {
 			*listFmt = "{{.String}}"

I also wonder if go list could take shortcuts when only parsing package names, perhaps avoid reading all .go files when the package name is found.

/cc @bcmills

@agnivade agnivade added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 4, 2018
@bcmills
Copy link
Contributor

bcmills commented Sep 14, 2018

Based on previous discussions with @rsc, I believe that go list is supposed to report more-or-less the same errors as go build. Determining whether an error exists is a non-trivial amount of work, although it's less work than building the package.

@bcmills
Copy link
Contributor

bcmills commented Sep 28, 2018

It seems like we could certainly do this if -e is also set: if we're explicitly ignoring errors and also not including them in the output, then there's no point in computing them.

@bcmills
Copy link
Contributor

bcmills commented Jan 17, 2019

Consolidating into #29666.

@bcmills bcmills closed this as completed Jan 17, 2019
@golang golang locked and limited conversation to collaborators Jan 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. ToolSpeed
Projects
None yet
Development

No branches or pull requests

4 participants