Skip to content

Commit

Permalink
cmd/go: uniq test log lines in computeTestInputsID
Browse files Browse the repository at this point in the history
Before this change, the same hashes were being computed multiple times
in some cases.

This gets the case reported in issue golang#26726 down from over 30s to .8s.
  • Loading branch information
Issac Trotts committed Aug 1, 2018
1 parent 6b9c782 commit 93cbf7b
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/cmd/go/internal/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,20 +1391,32 @@ func computeTestInputsID(a *work.Action, testlog []byte) (cache.ActionID, error)
testlog = bytes.TrimPrefix(testlog, testlogMagic)
h := cache.NewHash("testInputs")
pwd := a.Package.Dir

// Get the unique lines from the test log to save time by not computing
// the same hash more than once.
lineSet := make(map[string]bool)
for _, line := range bytes.Split(testlog, []byte("\n")) {
if len(line) == 0 {
continue
}
s := string(line)
i := strings.Index(s, " ")
lineSet[string(line)] = true
}
var lines []string
for l := range lineSet {
lines = append(lines, l)
}
sort.Strings(lines)

for _, line := range lines {
i := strings.Index(line, " ")
if i < 0 {
if cache.DebugTest {
fmt.Fprintf(os.Stderr, "testcache: %s: input list malformed (%q)\n", a.Package.ImportPath, line)
}
return cache.ActionID{}, errBadTestInputs
}
op := s[:i]
name := s[i+1:]
op := line[:i]
name := line[i+1:]
switch op {
default:
if cache.DebugTest {
Expand Down

0 comments on commit 93cbf7b

Please sign in to comment.