]> Cypherpunks repositories - gostls13.git/commit
cmd/go: avoid spurious readdir during fsys.Walk
authorRuss Cox <rsc@golang.org>
Wed, 6 Jul 2022 17:21:34 +0000 (13:21 -0400)
committerRuss Cox <rsc@golang.org>
Tue, 12 Jul 2022 09:11:26 +0000 (09:11 +0000)
commit913d05133c7fb3adfd2b1a34a47d635d8e072fa2
treeb429a1b5832f95d1615d2c659e1354834aefab16
parentd3d7998756c33f69706488cade1cd2b9b10a4c7f
cmd/go: avoid spurious readdir during fsys.Walk

fsys.Walk is cloned from filepath.Walk, which has always handled
a walk of a directory by reading the full directory before calling the
callback on the directory itself. So if the callback returns fs.SkipDir,
those entries are thrown away, but the expense of reading them was
still incurred. (Worse, this is the expensive directory read that also
calls Stat on every entry.) On machines with slow file system I/O,
these reads are particularly annoying. For example, if I do

go list m...

there is a call to filepath.Walk that is told about $GOROOT/src/archive
and responds by returning filepath.SkipDir because archive does not
start with m, but it only gets the chance to do that after the archive
directory has been read. (Same for all the other top-level directories.)
Even something like go list github.com/foo/bar/... reads every top-level
$GOPATH/src directory.

When we designed filepath.WalkDir, one of the changes we made was
to allow calling the callback twice for a directory: once before reading it,
and then possibly again if the read produces an error (uncommon).
This CL changes fsys.Walk to use that same model. None of the callbacks
need changing, but now the $GOROOT/src/archive and other top-level
directories won't be read when evaluating a pattern like 'm...'.

For #53577.
Fixes #53765.

Change-Id: Idfa3b9e2cc335417bfd9d66dd584cb16f92bd12e
Reviewed-on: https://go-review.googlesource.com/c/go/+/416179
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/go/internal/fsys/fsys.go
src/cmd/go/testdata/script/fsys_walk.txt [new file with mode: 0644]
src/cmd/go/testdata/script/list_perm.txt [moved from src/cmd/go/testdata/script/list_permissions.txt with 99% similarity]
src/cmd/go/testdata/script/mod_perm.txt [new file with mode: 0644]