Optimize mutator contexts
Mutator contexts are created for every module, and in the case of
transition mutator contexts for every dependency of every module.
Unlike the Blueprint mutator contexts that they wrap, the Soong
mutator contexts can be relatively large. Add global pools for all
of them that can avoid the repeated allocations.
Test: SOONG_PROFILE_MEM=/tmp/mem.pprof m nothing
Change-Id: I64a5f3c91292cff6352300f99c11ac50c713f96d
diff --git a/android/arch.go b/android/arch.go
index c39db02..b09a302 100644
--- a/android/arch.go
+++ b/android/arch.go
@@ -426,6 +426,7 @@
// filters out non-Soong modules. Now that we've handled them, create a
// normal android.BottomUpMutatorContext.
mctx := bottomUpMutatorContextFactory(bpctx, module, false)
+ defer bottomUpMutatorContextPool.Put(mctx)
base := module.base()
@@ -572,6 +573,7 @@
// filters out non-Soong modules. Now that we've handled them, create a
// normal android.BottomUpMutatorContext.
mctx := bottomUpMutatorContextFactory(bpctx, module, false)
+ defer bottomUpMutatorContextPool.Put(mctx)
base := module.base()