Open ijt opened 5 years ago
Perhaps related to https://github.com/golang/go/issues/26562.
I ran it again like this
GODEBUG=gocachehash=1 go test .
and the output seems to say that the same hashes are being recomputed many times.
...
HASH[getenv]
HASH[getenv]: "go1.10.3"
HASH[getenv]: "\x00"
HASH[getenv]: 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471
HASH[testInputs]: "env TMPDIR 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471\n"
HASH[getenv]
HASH[getenv]: "go1.10.3"
HASH[getenv]: "\x00"
HASH[getenv]: 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471
HASH[testInputs]: "env TMPDIR 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471\n"
HASH[getenv]
HASH[getenv]: "go1.10.3"
HASH[getenv]: "\x00"
HASH[getenv]: 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471
HASH[testInputs]: "env TMPDIR 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471\n"
HASH[getenv]
HASH[getenv]: "go1.10.3"
HASH[getenv]: "\x00"
HASH[getenv]: 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471
HASH[testInputs]: "env TMPDIR 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471\n"
HASH[getenv]
HASH[getenv]: "go1.10.3"
HASH[getenv]: "\x00"
HASH[getenv]: 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471
HASH[testInputs]: "env TMPDIR 213baadbc0781c1584c3a372b0c954145a41421235ba99e327ec0dd4f2326471\n"
HASH[testInputs]: 5650a478a2695895ea5dad0d10e315fe75f5d25b69bd3e0a20012a2c5adf2548
HASH subkey 422e11c5f77c95dbb5a70bf9d3f8cb86c84e52ac80a14030b5622b2fed39ed70 "inputs:5650a478a2695895ea5dad0d10e315fe75f5d25b69bd3e0a20012a2c5adf2548" = e3e7ae218e3b146458d106618002b8e7b2dbad22e5e8fd295d858549b0ac9ec0
ok github.com/google/go-cloud/wire/internal/wire (cached)
It looks like the check could be sped up a lot by only computing the hashes once.
Change https://golang.org/cl/127155 mentions this issue: cmd/go: check test cache more efficiently
I instrumented vgo test
and got this output from go tool pprof
:
It shows that the inDir
function takes up most of the time.
That lends support to the idea raised in issue #26562 that the slowdown was introduced in https://github.com/golang/go/commit/37d56279c87818b496e5717bddd1f7c43bfa743d.
Simplifying inDir
to no longer call EvalSymlinks
fixes the speed problem.
diff --git a/vendor/cmd/go/internal/test/test.go b/vendor/cmd/go/internal/test/test.go
index aff5ff2..02fc6cc 100644
--- a/vendor/cmd/go/internal/test/test.go
+++ b/vendor/cmd/go/internal/test/test.go
@@ -1429,15 +1429,7 @@ func computeTestInputsID(a *work.Action, testlog []byte) (cache.ActionID, error)
}
func inDir(path, dir string) bool {
- if str.HasFilePathPrefix(path, dir) {
- return true
- }
- xpath, err1 := filepath.EvalSymlinks(path)
- xdir, err2 := filepath.EvalSymlinks(dir)
- if err1 == nil && err2 == nil && str.HasFilePathPrefix(xpath, xdir) {
- return true
- }
- return false
+ return str.HasFilePathPrefix(path, dir)
}
The question is how to do it without giving up correctness.
The symlink issue is being fixed in #26562 already.
Change https://golang.org/cl/127635 mentions this issue: cmd/go: no longer eval symlinks in inDir
Closing this as a duplicate of #26562.
Change https://golang.org/cl/127715 mentions this issue: cmd/go: revert "cmd/go: no longer eval symlinks in inDir"
Change https://golang.org/cl/127818 mentions this issue: cmd/go: cache results of EvalSymlinks
I'd still really like to find a way to make the approach of CL 127635 - stop evaluating symlinks at all - work. I'll try to take a look in the next couple weeks.
I'd still really like to find a way to make the approach of CL 127635 - stop evaluating symlinks at all - work.
If anyone wants to make another run at this, the description for CL 127715 includes the output of the failing test.
Change https://go.dev/cl/511915 mentions this issue: cmd/go: cache results of EvalSymlinks
I'm able to consistently reproduce this while trying to test a fix for #64702.
Change https://go.dev/cl/563595 mentions this issue: cmd/go: change computeTestInputsID to use str.HasFilePathPrefix
What version of Go are you using (
go version
)?go1.10.2
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
What did you expect to see?
The second test run should have taken under 1s since nothing changed.
What did you see instead?
It took over 30s.
@zombiezen suggested that the slowness arises from the wire tests opening many packages under
$GOROOT
for type checking, makinggo test
spend a lot of time checking their hashes when deciding whether there is a cache hit.