Merge pull request #4981 from eatkins/startup-perf

Startup perf
This commit is contained in:
Ethan Atkins 2019-08-22 23:40:24 -07:00 committed by GitHub
commit 250a6ce29d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 12 deletions

View File

@ -234,7 +234,7 @@ trait Init[ScopeType] {
if (s.definitive) s :: Nil else ss :+ s
def addLocal(init: Seq[Setting[_]])(implicit scopeLocal: ScopeLocal): Seq[Setting[_]] =
init.flatMap(_.dependencies flatMap scopeLocal) ++ init
init.par.map(_.dependencies flatMap scopeLocal).toVector.flatten ++ init
def delegate(sMap: ScopedMap)(
implicit delegates: ScopeType => Seq[ScopeType],
@ -537,9 +537,9 @@ trait Init[ScopeType] {
// Take all the original defs and DerivedSettings along with locals, replace each DerivedSetting with the actual
// settings that were derived.
val allDefs = addLocal(init)(scopeLocal)
allDefs flatMap {
case d: DerivedSetting[_] => (derivedToStruct get d map (_.outputs)).toStream.flatten;
case s => Stream(s)
allDefs.flatMap {
case d: DerivedSetting[_] => (derivedToStruct get d map (_.outputs)).toSeq.flatten
case s => s :: Nil
}
}

View File

@ -25,6 +25,7 @@ import Scope.GlobalScope
import sbt.internal.parser.SbtParser
import sbt.io.IO
import scala.collection.JavaConverters._
/**
* This file is responsible for compiling the .sbt files used to configure sbt builds.
@ -340,11 +341,15 @@ object Index {
pairs.toMap[Task[_], ScopedKey[Task[_]]]
}
def allKeys(settings: Seq[Setting[_]]): Set[ScopedKey[_]] =
settings
.flatMap(s => if (s.key.key.isLocal) Nil else s.key +: s.dependencies)
.filter(!_.key.isLocal)
.toSet
def allKeys(settings: Seq[Setting[_]]): Set[ScopedKey[_]] = {
val result = new java.util.HashSet[ScopedKey[_]]
settings.foreach { s =>
if (!s.key.key.isLocal && result.add(s.key)) {
s.dependencies.foreach(k => if (!k.key.isLocal) result.add(s.key))
}
}
result.asScala.toSet
}
def attributeKeys(settings: Settings[Scope]): Set[AttributeKey[_]] =
settings.data.values.flatMap(_.keys).toSet[AttributeKey[_]]

View File

@ -28,10 +28,26 @@ object KeyIndex {
extra: BuildUtil[_],
projects: Map[URI, Set[String]],
configurations: Map[String, Seq[Configuration]]
): ExtendableKeyIndex =
(base(projects, configurations) /: known) { (index, key) =>
index.addAggregated(key, extra)
): ExtendableKeyIndex = {
/*
* Used to be:
* (base(projects, configurations) /: known) { (index, key) =>
* index.addAggregated(key, extra)
* }
* This was a significant serial bottleneck during project loading that we can work around by
* computing the aggregations in parallel and then bulk adding them to the index.
*/
val toAggregate = known.par.map {
case key if validID(key.key.label) =>
Aggregation.aggregate(key, ScopeMask(), extra, reverse = true)
case _ => Nil
}
(base(projects, configurations) /: toAggregate) {
case (index, Nil) => index
case (index, keys) => (index /: keys)(_ add _)
}
}
private[this] def base(
projects: Map[URI, Set[String]],
configurations: Map[String, Seq[Configuration]]