1
0
mirror of https://github.com/golang/go synced 2024-11-05 16:56:16 -07:00

godoc: parallelize corpus init

Massive win for high-latency network filesystems.
Also benefits the local disk/ssd case too, though.

R=golang-dev, bgarcia
CC=golang-dev
https://golang.org/cl/18650043
This commit is contained in:
Brad Fitzpatrick 2013-10-28 12:51:01 -07:00
parent e29626539b
commit 452c763fc7

View File

@ -73,13 +73,19 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i
list, _ := b.c.fs.ReadDir(path) list, _ := b.c.fs.ReadDir(path)
// determine number of subdirectories and if there are package files // determine number of subdirectories and if there are package files
ndirs := 0
hasPkgFiles := false hasPkgFiles := false
var dirchs []chan *Directory
var synopses [3]string // prioritized package documentation (0 == highest priority) var synopses [3]string // prioritized package documentation (0 == highest priority)
for _, d := range list { for _, d := range list {
switch { switch {
case isPkgDir(d): case isPkgDir(d):
ndirs++ ch := make(chan *Directory, 1)
dirchs = append(dirchs, ch)
go func(d os.FileInfo) {
name := d.Name()
ch <- b.newDirTree(fset, pathpkg.Join(path, name), name, depth+1)
}(d)
case isPkgFile(d): case isPkgFile(d):
// looks like a package file, but may just be a file ending in ".go"; // looks like a package file, but may just be a file ending in ".go";
// don't just count it yet (otherwise we may end up with hasPkgFiles even // don't just count it yet (otherwise we may end up with hasPkgFiles even
@ -112,20 +118,10 @@ func (b *treeBuilder) newDirTree(fset *token.FileSet, path, name string, depth i
// create subdirectory tree // create subdirectory tree
var dirs []*Directory var dirs []*Directory
if ndirs > 0 { for _, ch := range dirchs {
dirs = make([]*Directory, ndirs) if d := <-ch; d != nil {
i := 0 dirs = append(dirs, d)
for _, d := range list {
if isPkgDir(d) {
name := d.Name()
dd := b.newDirTree(fset, pathpkg.Join(path, name), name, depth+1)
if dd != nil {
dirs[i] = dd
i++
}
}
} }
dirs = dirs[0:i]
} }
// if there are no package files and no subdirectories // if there are no package files and no subdirectories