commit | 913d05133c7fb3adfd2b1a34a47d635d8e072fa2 | [log] [tgz] |
---|---|---|
author | Russ Cox <rsc@golang.org> | Wed Jul 06 13:21:34 2022 -0400 |
committer | Russ Cox <rsc@golang.org> | Tue Jul 12 09:11:26 2022 +0000 |
tree | b429a1b5832f95d1615d2c659e1354834aefab16 | |
parent | d3d7998756c33f69706488cade1cd2b9b10a4c7f [diff] |
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>
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.