Add comments

This commit is contained in:
Adrien Piquerez 2024-11-05 11:36:18 +01:00
parent 9382fc99b7
commit 2f726cddf0
3 changed files with 9 additions and 0 deletions

View File

@ -337,6 +337,8 @@ object Project:
[a] => (k: ScopedKey[a]) => ScopedKey(f(k.scope), k.key)
def transform(g: Scope => Scope, ss: Seq[Def.Setting[?]]): Seq[Def.Setting[?]] =
// We use caching to avoid creating new Scope instances too many times
// Creating a new Scope is CPU expensive because of the uniqueness cache
val f = mapScope(Util.withCaching(g))
ss.map(_.mapKey(f).mapReferenced(f))

View File

@ -23,6 +23,8 @@ final case class Scope private (
task: ScopeAxis[AttributeKey[?]],
extra: ScopeAxis[AttributeMap]
):
// Since we use a uniqueness cache we can pre-compute the hashCode for free
// It is always going to be used at least once
override val hashCode = ScalaRunTime._hashCode(this)
def rescope(project: Reference): Scope = copy(project = Select(project))
@ -43,6 +45,9 @@ final case class Scope private (
end Scope
object Scope:
// We use a global uniqueness cache to avoid duplicating Scope.
// At the time of writing, it divides the number of long-living instances by 15
// reducing the pressure on the heap, and speed up the loading.
private val uniquenessCache = TrieMap.empty[Scope, Scope]
def apply(

View File

@ -274,6 +274,8 @@ private[sbt] object Load {
finalTransforms(settings0)
}
val delegates = timed("Load.apply: config.delegates", log) {
// We use caching to avoid creating new Scope instances too many times
// Creating a new Scope is CPU expensive because of the uniqueness cache
Util.withCaching(config.delegates(loaded))
}
val (cMap, data) = timed("Load.apply: Def.make(settings)...", log) {