Optimize updateDependencies
Avoid reallocating module.forwardDeps and module.reverseDeps every time through updateDependencies by resetting the slices without reducing their capacity. Accumulate dependencies to visit directly into module.forwardDeps. Use a loop instead of a map to check for duplicates, average number of dependencies is measured to be 9.5, although there are a few outliers with up to 2108. Reduces mean soong_build execution time on internal master from 87s to 82.7s (5%). Test: context_test.go Change-Id: I58fcd5514e494bafa965443461851b21b7bce382
This commit is contained in:
parent
bcd5686660
commit
7ff2e8d2a4
1 changed files with 15 additions and 8 deletions
23
context.go
23
context.go
|
@ -1355,6 +1355,8 @@ func (c *Context) createVariations(origModule *moduleInfo, mutatorName string,
|
||||||
m := *origModule
|
m := *origModule
|
||||||
newModule := &m
|
newModule := &m
|
||||||
newModule.directDeps = append([]depInfo(nil), origModule.directDeps...)
|
newModule.directDeps = append([]depInfo(nil), origModule.directDeps...)
|
||||||
|
newModule.reverseDeps = nil
|
||||||
|
newModule.forwardDeps = nil
|
||||||
newModule.logicModule = newLogicModule
|
newModule.logicModule = newLogicModule
|
||||||
newModule.variant = newVariant(origModule, mutatorName, variationName, local)
|
newModule.variant = newVariant(origModule, mutatorName, variationName, local)
|
||||||
newModule.properties = newProperties
|
newModule.properties = newProperties
|
||||||
|
@ -2180,7 +2182,9 @@ func (c *Context) updateDependencies() (errs []error) {
|
||||||
checking[module] = true
|
checking[module] = true
|
||||||
defer delete(checking, module)
|
defer delete(checking, module)
|
||||||
|
|
||||||
deps := make(map[*moduleInfo]bool)
|
// Reset the forward and reverse deps without reducing their capacity to avoid reallocation.
|
||||||
|
module.reverseDeps = module.reverseDeps[:0]
|
||||||
|
module.forwardDeps = module.forwardDeps[:0]
|
||||||
|
|
||||||
// Add an implicit dependency ordering on all earlier modules in the same module group
|
// Add an implicit dependency ordering on all earlier modules in the same module group
|
||||||
for _, dep := range module.group.modules {
|
for _, dep := range module.group.modules {
|
||||||
|
@ -2188,18 +2192,22 @@ func (c *Context) updateDependencies() (errs []error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if depModule := dep.module(); depModule != nil {
|
if depModule := dep.module(); depModule != nil {
|
||||||
deps[depModule] = true
|
module.forwardDeps = append(module.forwardDeps, depModule)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outer:
|
||||||
for _, dep := range module.directDeps {
|
for _, dep := range module.directDeps {
|
||||||
deps[dep.module] = true
|
// use a loop to check for duplicates, average number of directDeps measured to be 9.5.
|
||||||
|
for _, exists := range module.forwardDeps {
|
||||||
|
if dep.module == exists {
|
||||||
|
continue outer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
module.forwardDeps = append(module.forwardDeps, dep.module)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.reverseDeps = []*moduleInfo{}
|
for _, dep := range module.forwardDeps {
|
||||||
module.forwardDeps = []*moduleInfo{}
|
|
||||||
|
|
||||||
for dep := range deps {
|
|
||||||
if checking[dep] {
|
if checking[dep] {
|
||||||
// This is a cycle.
|
// This is a cycle.
|
||||||
return []*moduleInfo{dep, module}
|
return []*moduleInfo{dep, module}
|
||||||
|
@ -2225,7 +2233,6 @@ func (c *Context) updateDependencies() (errs []error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.forwardDeps = append(module.forwardDeps, dep)
|
|
||||||
dep.reverseDeps = append(dep.reverseDeps, module)
|
dep.reverseDeps = append(dep.reverseDeps, module)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue