Add scala reflect layer

Not caching scala reflect is extremely painful if the build uses
scalatest. It adds O(1second) to my watch performance benchmarks. It
actually made sbt 1.3.0 much slower than 0.13.17
This commit is contained in:
Ethan Atkins 2019-05-30 16:42:02 -07:00
parent cf73bbbafc
commit 5faf78af96
1 changed files with 12 additions and 5 deletions

View File

@ -105,7 +105,7 @@ private[sbt] object ClassLoaders {
}
/*
* Create a layered classloader. There are up to four layers:
* 1) the scala instance class loader
* 1) the scala instance class loader (may actually be two layers if scala-reflect is used)
* 2) the resource layer
* 3) the dependency jars
* 4) the rest of the classpath
@ -135,11 +135,18 @@ private[sbt] object ClassLoaders {
val scalaLibraryLayer = layer(si.libraryJars, interfaceLoader, cache, resources, tmp)
val cpFiles = fullCP.map(_._1)
val scalaReflectJar = allDependencies.find(_.getName == "scala-reflect.jar")
val scalaReflectLayer = scalaReflectJar
.map { file =>
layer(file :: Nil, scalaLibraryLayer, cache, resources, tmp)
}
.getOrElse(scalaLibraryLayer)
// layer 2 (resources)
val resourceLayer =
if (layerDependencies)
getResourceLayer(cpFiles, resourceCP, scalaLibraryLayer, cache, resources)
else scalaLibraryLayer
getResourceLayer(cpFiles, resourceCP, scalaReflectLayer, cache, resources)
else scalaReflectLayer
// layer 3 (optional if in the test config and the runtime layer is not shared)
val dependencyLayer =
@ -148,8 +155,8 @@ private[sbt] object ClassLoaders {
// layer 4
val filteredSet =
if (layerDependencies) allDependencies.toSet ++ si.libraryJars
else Set(si.libraryJars: _*)
if (layerDependencies) allDependencies.toSet ++ si.libraryJars ++ scalaReflectJar
else Set(si.libraryJars ++ scalaReflectJar: _*)
val dynamicClasspath = cpFiles.filterNot(filteredSet)
new LayeredClassLoader(dynamicClasspath, dependencyLayer, resources, tmp)
}