Skip to content

cmd/go: check test cache more efficiently #26732

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 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,35 @@ 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)
}
// Iterating over the map means the unique lines are in random order.
// Sorting puts them in a deterministic order so the hashing below will
// get the same result if the set of log lines is the same.
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