Skip to content

Commit 8efa10c

Browse files
committed
internal/imports: add a benchmark for the initial mod cache scan
In CL 508506, we missed a performance regression because there were no benchmarks for goimports' initial scan: the only scan benchmark related to re-scanning, which doesn't recursively descend into all module cache directories. Add a benchmark for the initial scan. For golang/go#44863 Change-Id: I94ec8b2b0df468fd06a1316f24c00d5f47c2f5c9 Reviewed-on: https://go-review.googlesource.com/c/tools/+/561436 Reviewed-by: Alan Donovan <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent df03d7d commit 8efa10c

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

internal/imports/mod_test.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,7 @@ import (
12891289
}
12901290
}
12911291

1292-
func BenchmarkScanModCache(b *testing.B) {
1292+
func BenchmarkModuleResolver_RescanModCache(b *testing.B) {
12931293
env := &ProcessEnv{
12941294
GocmdRunner: &gocommand.Runner{},
12951295
// Uncomment for verbose logging (too verbose to enable by default).
@@ -1309,3 +1309,17 @@ func BenchmarkScanModCache(b *testing.B) {
13091309
resolver.(*ModuleResolver).ClearForNewScan()
13101310
}
13111311
}
1312+
1313+
func BenchmarkModuleResolver_InitialScan(b *testing.B) {
1314+
for i := 0; i < b.N; i++ {
1315+
env := &ProcessEnv{
1316+
GocmdRunner: &gocommand.Runner{},
1317+
}
1318+
exclude := []gopathwalk.RootType{gopathwalk.RootGOROOT}
1319+
resolver, err := env.GetResolver()
1320+
if err != nil {
1321+
b.Fatal(err)
1322+
}
1323+
scanToSlice(resolver, exclude)
1324+
}
1325+
}

0 commit comments

Comments
 (0)