]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't call ImportDir unnecessarily
authorAnthony Martin <ality@pbrane.org>
Fri, 22 Feb 2013 04:09:31 +0000 (20:09 -0800)
committerAnthony Martin <ality@pbrane.org>
Fri, 22 Feb 2013 04:09:31 +0000 (20:09 -0800)
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

src/cmd/go/main.go

index a7841d2655133a582f1e7a93e806600f8a63b5ec..bf1dad40f3455370a3da8860aa739bc4a1eba309 100644 (file)
@@ -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
                })
        }