Cache delegates during Load

This commit is contained in:
Adrien Piquerez 2024-11-01 17:57:42 +01:00
parent 5bbe871882
commit 8b5eaa2cd5
2 changed files with 13 additions and 2 deletions

View File

@ -10,6 +10,8 @@ package sbt.internal.util
import java.util.Locale
import scala.collection.concurrent.TrieMap
object Util {
def makeList[T](size: Int, value: T): List[T] = List.fill(size)(value)
@ -71,4 +73,9 @@ object Util {
extension [A](value: A) {
def some: Option[A] = (Some(value): Option[A])
}
private[sbt] def withCaching[A1, A2](f: A1 => A2): A1 => A2 = {
val cache = TrieMap.empty[A1, A2]
x => cache.getOrElseUpdate(x, f(x))
}
}

View File

@ -35,6 +35,7 @@ import java.net.URI
import java.nio.file.{ Path, Paths }
import scala.annotation.tailrec
import scala.collection.mutable
import sbt.internal.util.Util
private[sbt] object Load {
// note that there is State passed in but not pulled out
@ -266,11 +267,14 @@ private[sbt] object Load {
}
val projects = loaded.units
lazy val rootEval = lazyEval(loaded.units(loaded.root).unit)
val settings0 = timed("Load.apply: buildConfigurations", log) {
buildConfigurations(loaded, getRootProject(projects), config.injectSettings)
}
val settings = timed("Load.apply: finalTransforms", log) {
finalTransforms(buildConfigurations(loaded, getRootProject(projects), config.injectSettings))
finalTransforms(settings0)
}
val delegates = timed("Load.apply: config.delegates", log) {
config.delegates(loaded)
Util.withCaching(config.delegates(loaded))
}
val (cMap, data) = timed("Load.apply: Def.make(settings)...", log) {
// When settings.size is 100000, Def.make takes around 10s.