From 11b0c7b3ffb47e6dfbf4d2fc0710cafb10ee19d5 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Fri, 18 Oct 2013 19:56:40 -0400 Subject: [PATCH] Process settings once in SettingGraph for better performance. Running 'inspect tree sbt/update' on sbt goes from 27 s to <1 s. Review by @eed3si9n. --- main/src/main/scala/sbt/SettingGraph.scala | 26 +++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/main/src/main/scala/sbt/SettingGraph.scala b/main/src/main/scala/sbt/SettingGraph.scala index a0a471b46..e8c9433e7 100644 --- a/main/src/main/scala/sbt/SettingGraph.scala +++ b/main/src/main/scala/sbt/SettingGraph.scala @@ -13,18 +13,22 @@ object SettingGraph def apply(structure: BuildStructure, basedir: File, scoped: ScopedKey[_], generation: Int) (implicit display: Show[ScopedKey[_]]): SettingGraph = { - val key = scoped.key - val scope = scoped.scope - val definedIn = structure.data.definingScope(scope, key) map { sc => display(ScopedKey(sc, key)) } val cMap = flattenLocals(compiled(structure.settings, false)(structure.delegates, structure.scopeLocal, display)) - // val related = cMap.keys.filter(k => k.key == key && k.scope != scope) - val depends = cMap.get(scoped) match { case Some(c) => c.dependencies.toSet; case None => Set.empty } - // val reverse = reverseDependencies(cMap, scoped) - - SettingGraph(display(scoped), definedIn, - Project.scopedKeyData(structure, scope, key), - key.description, basedir, - depends map { (x: ScopedKey[_]) => apply(structure, basedir, x, generation + 1) }) + def loop(scoped: ScopedKey[_], generation: Int): SettingGraph = + { + val key = scoped.key + val scope = scoped.scope + val definedIn = structure.data.definingScope(scope, key) map { sc => display(ScopedKey(sc, key)) } + val depends = cMap.get(scoped) match { case Some(c) => c.dependencies.toSet; case None => Set.empty } + // val related = cMap.keys.filter(k => k.key == key && k.scope != scope) + // val reverse = reverseDependencies(cMap, scoped) + + SettingGraph(display(scoped), definedIn, + Project.scopedKeyData(structure, scope, key), + key.description, basedir, + depends map { (x: ScopedKey[_]) => loop(x, generation + 1) }) + } + loop(scoped, generation) } }