diff options
author | 2023-05-15 21:50:29 +0000 | |
---|---|---|
committer | 2023-05-19 18:01:35 +0000 | |
commit | e59c0db5360b850b444c3bed9b92b0fd30b15e1e (patch) | |
tree | 0dba113aa64c5402cc630a1ab2e1aadd2a1e1676 | |
parent | fcb86824be33eea38a2a4e766c37929cf043b9f8 (diff) |
android: Allow running some singletons in parallel.
Many of the singletons are trivial and can be run in parallel, improving
the performance during analysis.
Bug: 281536768
Test: manual, presubmit
Change-Id: I989333e2ff3fe71783601f27bf5e0732a1b4ea61
-rw-r--r-- | android/register.go | 52 | ||||
-rw-r--r-- | android/testing.go | 12 |
2 files changed, 51 insertions, 13 deletions
diff --git a/android/register.go b/android/register.go index 1a3db9d90..c57964c18 100644 --- a/android/register.go +++ b/android/register.go @@ -65,16 +65,19 @@ type singleton struct { // True if this should be registered as a pre-singleton, false otherwise. pre bool + // True if this should be registered as a parallel singleton. + parallel bool + name string factory SingletonFactory } -func newSingleton(name string, factory SingletonFactory) singleton { - return singleton{false, name, factory} +func newSingleton(name string, factory SingletonFactory, parallel bool) singleton { + return singleton{pre: false, parallel: parallel, name: name, factory: factory} } func newPreSingleton(name string, factory SingletonFactory) singleton { - return singleton{true, name, factory} + return singleton{pre: true, parallel: false, name: name, factory: factory} } func (s singleton) componentName() string { @@ -86,7 +89,7 @@ func (s singleton) register(ctx *Context) { if s.pre { ctx.RegisterPreSingletonType(s.name, adaptor) } else { - ctx.RegisterSingletonType(s.name, adaptor) + ctx.RegisterSingletonType(s.name, adaptor, s.parallel) } } @@ -145,8 +148,16 @@ func RegisterModuleTypeForDocs(name string, factory reflect.Value) { moduleTypeByFactory[factory] = name } +func registerSingletonType(name string, factory SingletonFactory, parallel bool) { + singletons = append(singletons, newSingleton(name, factory, parallel)) +} + func RegisterSingletonType(name string, factory SingletonFactory) { - singletons = append(singletons, newSingleton(name, factory)) + registerSingletonType(name, factory, false) +} + +func RegisterParallelSingletonType(name string, factory SingletonFactory) { + registerSingletonType(name, factory, true) } func RegisterPreSingletonType(name string, factory SingletonFactory) { @@ -220,17 +231,17 @@ func (ctx *Context) registerSingletonMakeVarsProvider(makevars SingletonMakeVars func collateGloballyRegisteredSingletons() sortableComponents { allSingletons := append(sortableComponents(nil), singletons...) allSingletons = append(allSingletons, - singleton{false, "bazeldeps", BazelSingleton}, + singleton{pre: false, parallel: false, name: "bazeldeps", factory: BazelSingleton}, // Register phony just before makevars so it can write out its phony rules as Make rules - singleton{false, "phony", phonySingletonFactory}, + singleton{pre: false, parallel: false, name: "phony", factory: phonySingletonFactory}, // Register makevars after other singletons so they can export values through makevars - singleton{false, "makevars", makeVarsSingletonFunc}, + singleton{pre: false, parallel: false, name: "makevars", factory: makeVarsSingletonFunc}, // Register env and ninjadeps last so that they can track all used environment variables and // Ninja file dependencies stored in the config. - singleton{false, "ninjadeps", ninjaDepsSingletonFactory}, + singleton{pre: false, parallel: false, name: "ninjadeps", factory: ninjaDepsSingletonFactory}, ) return allSingletons @@ -259,7 +270,9 @@ func ModuleTypeByFactory() map[reflect.Value]string { type RegistrationContext interface { RegisterModuleType(name string, factory ModuleFactory) RegisterSingletonModuleType(name string, factory SingletonModuleFactory) + RegisterParallelSingletonModuleType(name string, factory SingletonModuleFactory) RegisterPreSingletonType(name string, factory SingletonFactory) + RegisterParallelSingletonType(name string, factory SingletonFactory) RegisterSingletonType(name string, factory SingletonFactory) PreArchMutators(f RegisterMutatorFunc) @@ -315,8 +328,15 @@ func (ctx *initRegistrationContext) RegisterModuleType(name string, factory Modu } func (ctx *initRegistrationContext) RegisterSingletonModuleType(name string, factory SingletonModuleFactory) { + ctx.registerSingletonModuleType(name, factory, false) +} +func (ctx *initRegistrationContext) RegisterParallelSingletonModuleType(name string, factory SingletonModuleFactory) { + ctx.registerSingletonModuleType(name, factory, true) +} + +func (ctx *initRegistrationContext) registerSingletonModuleType(name string, factory SingletonModuleFactory, parallel bool) { s, m := SingletonModuleFactoryAdaptor(name, factory) - ctx.RegisterSingletonType(name, s) + ctx.registerSingletonType(name, s, parallel) ctx.RegisterModuleType(name, m) // Overwrite moduleTypesForDocs with the original factory instead of the lambda returned by // SingletonModuleFactoryAdaptor so that docs can find the module type documentation on the @@ -324,12 +344,20 @@ func (ctx *initRegistrationContext) RegisterSingletonModuleType(name string, fac RegisterModuleTypeForDocs(name, reflect.ValueOf(factory)) } -func (ctx *initRegistrationContext) RegisterSingletonType(name string, factory SingletonFactory) { +func (ctx *initRegistrationContext) registerSingletonType(name string, factory SingletonFactory, parallel bool) { if _, present := ctx.singletonTypes[name]; present { panic(fmt.Sprintf("singleton type %q is already registered", name)) } ctx.singletonTypes[name] = factory - RegisterSingletonType(name, factory) + registerSingletonType(name, factory, parallel) +} + +func (ctx *initRegistrationContext) RegisterSingletonType(name string, factory SingletonFactory) { + ctx.registerSingletonType(name, factory, false) +} + +func (ctx *initRegistrationContext) RegisterParallelSingletonType(name string, factory SingletonFactory) { + ctx.registerSingletonType(name, factory, true) } func (ctx *initRegistrationContext) RegisterPreSingletonType(name string, factory SingletonFactory) { diff --git a/android/testing.go b/android/testing.go index 2a9c6584e..5ad7ad07f 100644 --- a/android/testing.go +++ b/android/testing.go @@ -495,8 +495,18 @@ func (ctx *TestContext) RegisterSingletonModuleType(name string, factory Singlet ctx.RegisterModuleType(name, m) } +func (ctx *TestContext) RegisterParallelSingletonModuleType(name string, factory SingletonModuleFactory) { + s, m := SingletonModuleFactoryAdaptor(name, factory) + ctx.RegisterParallelSingletonType(name, s) + ctx.RegisterModuleType(name, m) +} + func (ctx *TestContext) RegisterSingletonType(name string, factory SingletonFactory) { - ctx.singletons = append(ctx.singletons, newSingleton(name, factory)) + ctx.singletons = append(ctx.singletons, newSingleton(name, factory, false)) +} + +func (ctx *TestContext) RegisterParallelSingletonType(name string, factory SingletonFactory) { + ctx.singletons = append(ctx.singletons, newSingleton(name, factory, true)) } func (ctx *TestContext) RegisterPreSingletonType(name string, factory SingletonFactory) { |