From: Anthony Martin Date: Fri, 22 Feb 2013 04:09:31 +0000 (-0800) Subject: cmd/go: don't call ImportDir unnecessarily X-Git-Tag: go1.1rc2~906 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ed1ac056735e67c0f6bc23c60a9c2a0f999c80cb;p=gostls13.git cmd/go: don't call ImportDir unnecessarily This significantly speeds up the go tool on slow file systems (or those with cold caches). The following numbers were obtained using an encrypted ext4 file system running on Linux 3.7.9. # Before $ sudo sysctl -w 'vm.drop_caches=3' $ time go list code.google.com/p/go.net/... | wc -l 9 real 0m16.921s user 0m0.637s sys 0m0.317s # After $ sudo sysctl -w 'vm.drop_caches=3' $ time go list code.google.com/p/go.net/... | wc -l 9 real 0m8.175s user 0m0.220s sys 0m0.177s R=rsc, r CC=golang-dev https://golang.org/cl/7369044 --- diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index a7841d2655..bf1dad40f3 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -453,19 +453,20 @@ func matchPackages(pattern string) []string { return filepath.SkipDir } + // We use, e.g., cmd/gofmt as the pseudo import path for gofmt. + name = "cmd/" + name + if have[name] { + return nil + } + have[name] = true + if !match(name) { + return nil + } _, err = buildContext.ImportDir(path, 0) if err != nil { return nil } - - // We use, e.g., cmd/gofmt as the pseudo import path for gofmt. - name = "cmd/" + name - if !have[name] { - have[name] = true - if match(name) { - pkgs = append(pkgs, name) - } - } + pkgs = append(pkgs, name) return nil }) @@ -493,14 +494,14 @@ func matchPackages(pattern string) []string { return nil } have[name] = true - + if !match(name) { + return nil + } _, err = buildContext.ImportDir(path, 0) if err != nil && strings.Contains(err.Error(), "no Go source files") { return nil } - if match(name) { - pkgs = append(pkgs, name) - } + pkgs = append(pkgs, name) return nil }) }