Skip to content

Commit

Permalink
internal/imports: add a benchmark for the initial mod cache scan
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
findleyr committed Feb 5, 2024
1 parent df03d7d commit 8efa10c
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion internal/imports/mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,7 @@ import (
}
}

func BenchmarkScanModCache(b *testing.B) {
func BenchmarkModuleResolver_RescanModCache(b *testing.B) {
env := &ProcessEnv{
GocmdRunner: &gocommand.Runner{},
// Uncomment for verbose logging (too verbose to enable by default).
Expand All @@ -1309,3 +1309,17 @@ func BenchmarkScanModCache(b *testing.B) {
resolver.(*ModuleResolver).ClearForNewScan()
}
}

func BenchmarkModuleResolver_InitialScan(b *testing.B) {
for i := 0; i < b.N; i++ {
env := &ProcessEnv{
GocmdRunner: &gocommand.Runner{},
}
exclude := []gopathwalk.RootType{gopathwalk.RootGOROOT}
resolver, err := env.GetResolver()
if err != nil {
b.Fatal(err)
}
scanToSlice(resolver, exclude)
}
}

0 comments on commit 8efa10c

Please sign in to comment.