1
0
mirror of https://github.com/golang/go synced 2024-11-23 05:10:09 -07:00

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
This commit is contained in:
Anthony Martin 2013-02-21 20:09:31 -08:00
parent edc3126e98
commit ed1ac05673

View 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
})
}