aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOphestra <cat@gensokyo.uk>2026-04-03 20:50:09 +0900
committerOphestra <cat@gensokyo.uk>2026-04-03 20:58:23 +0900
commit3d54d1f1767398e8cd17db34047203e090d2a9a9 (patch)
tree0605eb5e40feb4f0d4f4db8a9169d86c035fb4e1
parent9feac7738f5dbe9f2f32cfa297582d3b520cb049 (diff)
internal/rosa: drop caches
This enables accurate benchmarking of the toolchain abstraction. Signed-off-by: Ophestra <cat@gensokyo.uk>
-rw-r--r--internal/rosa/all.go11
-rw-r--r--internal/rosa/all_test.go12
-rw-r--r--internal/rosa/rosa_test.go10
3 files changed, 33 insertions, 0 deletions
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/all_test.go b/internal/rosa/all_test.go
index 407dc178..f97ebbdf 100644
--- a/internal/rosa/all_test.go
+++ b/internal/rosa/all_test.go
@@ -19,6 +19,18 @@ func TestLoad(t *testing.T) {
}
}
+func BenchmarkAll(b *testing.B) {
+ for b.Loop() {
+ for i := range rosa.PresetEnd {
+ rosa.Std.Load(rosa.PArtifact(i))
+ }
+
+ b.StopTimer()
+ rosa.DropCaches()
+ b.StartTimer()
+ }
+}
+
func TestResolveName(t *testing.T) {
t.Parallel()
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()
+ }
+}