diff --git a/internal/rosa/all.go b/internal/rosa/all.go index 4b87ed69..fefd3863 100644 --- a/internal/rosa/all.go +++ b/internal/rosa/all.go @@ -307,6 +307,17 @@ var ( artifactsOnce [_toolchainEnd][len(artifactsM)]sync.Once ) +// zero zeros the value pointed to by p. +func zero[T any](p *T) { var v T; *p = v } + +// DropCaches arranges for all cached [pkg.Artifact] to be freed some time after +// it returns. Must not be used concurrently with any other function from this +// package. +func DropCaches() { + zero(&artifacts) + zero(&artifactsOnce) +} + // GetMetadata returns [Metadata] of a [PArtifact]. func GetMetadata(p PArtifact) *Metadata { return &artifactsM[p] } diff --git a/internal/rosa/rosa_test.go b/internal/rosa/rosa_test.go index 18d7b99b..ba51b248 100644 --- a/internal/rosa/rosa_test.go +++ b/internal/rosa/rosa_test.go @@ -91,3 +91,13 @@ func TestCureAll(t *testing.T) { }) } } + +func BenchmarkStage3(b *testing.B) { + for b.Loop() { + rosa.Std.Load(rosa.LLVMClang) + + b.StopTimer() + rosa.DropCaches() + b.StartTimer() + } +}