From 5f2d41621915c0ff5337470915d18d167f6d20a0 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Tue, 5 Dec 2017 22:29:57 -0800 Subject: Hackily speed up repeated Scala compiles by keeping a global cache of hot ScalaInstance/Classloader instances around between compiles --- .../main/scala/mill/scalaplugin/ScalaModule.scala | 33 ++++++++-------------- .../scala/mill/scalaplugin/TestEvaluator.scala | 2 +- 2 files changed, 12 insertions(+), 23 deletions(-) (limited to 'scalaplugin') diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index 001f5844..49d9660f 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -51,7 +51,6 @@ object ScalaModule{ .toIO } - val compilerJars = compilerClasspath.toArray.map(_.toIO) def binaryScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".") val compilerBridgeJar = new java.io.File( @@ -60,7 +59,7 @@ object ScalaModule{ ) val classloaderSig = compilerClasspath.map(p => p.toString().hashCode + p.mtime.toMillis).sum - println("classloaderSig: " + classloaderSig) + val scalaInstance = scalaInstanceCache match{ case Some((k, v)) if k == classloaderSig => v case _ => @@ -76,16 +75,11 @@ object ScalaModule{ scalaInstance } - - - val scalac = ZincUtil.scalaCompiler(scalaInstance, compilerBridgeJar) - mkdir(ctx.dest) val ic = new sbt.internal.inc.IncrementalCompilerImpl() val logger = { - val consoleAppender = MainAppender.defaultScreen(ConsoleOut.printStreamOut( ctx.log.outputStream )) @@ -94,23 +88,13 @@ object ScalaModule{ LogExchange.bindLoggerAppenders("Hello", (consoleAppender -> sbt.util.Level.Info) :: Nil) l } - val compiler = new IncrementalCompilerImpl - - - val cs = compiler.compilers(scalaInstance, ClasspathOptionsUtil.boot, None, scalac) val lookup = MockedLookup(Function.const(Optional.empty[CompileAnalysis])) - val reporter = new ManagedLoggedReporter(10, logger) - val extra = Array(InterfaceUtil.t2(("key", "value"))) - - val ignoreProgress = new CompileProgress { - override def advance(current: Int, total: Int): Boolean = true - override def startUnit(phase: String, unitPath: String): Unit = () - } val zincFile = (ctx.dest/'zinc).toIO val store = FileAnalysisStore.binary(zincFile) val classesDir = (ctx.dest / 'classes).toIO + val newResult = ic.compile( ic.inputs( classpath = classesDir +: compileClasspathFiles, @@ -121,16 +105,21 @@ object ScalaModule{ maxErrors = 10, sourcePositionMappers = Array(), order = CompileOrder.Mixed, - compilers = cs, + compilers = ic.compilers( + scalaInstance, + ClasspathOptionsUtil.boot, + None, + ZincUtil.scalaCompiler(scalaInstance, compilerBridgeJar) + ), setup = ic.setup( lookup, skip = false, zincFile, new FreshCompilerCache, IncOptions.of(), - reporter, - Some(ignoreProgress), - extra + new ManagedLoggedReporter(10, logger), + None, + Array() ), pr = { val prev = store.get() diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala b/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala index 242b4e8b..f0593e2a 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala @@ -16,7 +16,7 @@ object TestEvaluator { def eval[T]( mapping: Map[Target[_], Mirror.LabelledTarget[_]], workspacePath: Path)(t: Task[T]): Either[Result.Failing, (T, Int)] = { - val evaluator = new Evaluator(workspacePath, mapping, new PrintLogger(true)) + val evaluator = new Evaluator(workspacePath, mapping, DummyLogger) val evaluated = evaluator.evaluate(OSet(t)) if (evaluated.failing.keyCount == 0) { -- cgit v1.2.3