Skip to content

Commit

Permalink
Avoid intermediate mapping in ZincWorkerImpl (#2661)
Browse files Browse the repository at this point in the history
Profiled Mill compiling Mill itself and 0.07% of the time was spent in
mapping the result of `compileMixed0` to `CompilationResult`.
This changes the `compileInternal` method to already use the right types
so less conversions are needed.

Pull request: #2661
  • Loading branch information
lolgab authored Jul 16, 2023
1 parent 1e5871a commit 95c2ea2
Showing 1 changed file with 5 additions and 56 deletions.
61 changes: 5 additions & 56 deletions scalalib/worker/src/mill/scalalib/worker/ZincWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -297,26 +297,6 @@ class ZincWorkerImpl(
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = {

for (
res <- compileJava0(
upstreamCompileOutput = upstreamCompileOutput.map(c => (c.analysisFile, c.classes.path)),
sources = sources,
compileClasspath = compileClasspath,
javacOptions = javacOptions,
reporter = reporter,
reportCachedProblems = reportCachedProblems
)
) yield CompilationResult(res._1, PathRef(res._2))
}
def compileJava0(
upstreamCompileOutput: Seq[(os.Path, os.Path)],
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[(os.Path, os.Path)] = {
compileInternal(
upstreamCompileOutput = upstreamCompileOutput,
sources = sources,
Expand All @@ -342,37 +322,6 @@ class ZincWorkerImpl(
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = {

for (
res <- compileMixed0(
upstreamCompileOutput.map(c => (c.analysisFile, c.classes.path)),
sources,
compileClasspath,
javacOptions,
scalaVersion,
scalaOrganization,
scalacOptions,
compilerClasspath,
scalacPluginClasspath,
reporter,
reportCachedProblems
)
) yield CompilationResult(res._1, PathRef(res._2))
}

def compileMixed0(
upstreamCompileOutput: Seq[(os.Path, os.Path)],
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
scalaVersion: String,
scalaOrganization: String,
scalacOptions: Seq[String],
compilerClasspath: Agg[PathRef],
scalacPluginClasspath: Agg[PathRef],
reporter: Option[CompileProblemReporter],
reportOldProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[(os.Path, os.Path)] = {
withCompilers(
scalaVersion = scalaVersion,
scalaOrganization = scalaOrganization,
Expand All @@ -388,7 +337,7 @@ class ZincWorkerImpl(
scalacOptions = scalacOptions,
compilers = compilers,
reporter = reporter,
reportOldProblems: Boolean
reportCachedProblems: Boolean
)
}
}
Expand Down Expand Up @@ -463,15 +412,15 @@ class ZincWorkerImpl(
}

private def compileInternal(
upstreamCompileOutput: Seq[(os.Path, os.Path)],
upstreamCompileOutput: Seq[CompilationResult],
sources: Agg[os.Path],
compileClasspath: Agg[os.Path],
javacOptions: Seq[String],
scalacOptions: Seq[String],
compilers: Compilers,
reporter: Option[CompileProblemReporter],
reportCachedProblems: Boolean
)(implicit ctx: ZincWorkerApi.Ctx): Result[(os.Path, os.Path)] = {
)(implicit ctx: ZincWorkerApi.Ctx): Result[CompilationResult] = {
os.makeDir.all(ctx.dest)

reporter.foreach(_.start())
Expand Down Expand Up @@ -512,7 +461,7 @@ class ZincWorkerImpl(
}
}
}
val analysisMap0 = upstreamCompileOutput.map(_.swap).toMap
val analysisMap0 = upstreamCompileOutput.map(c => c.classes.path -> c.analysisFile).toMap

def analysisMap(f: VirtualFile): Optional[CompileAnalysis] = {
val analysisFile = f match {
Expand Down Expand Up @@ -615,7 +564,7 @@ class ZincWorkerImpl(
newResult.setup()
)
)
Result.Success((zincFile, classesDir))
Result.Success(CompilationResult(zincFile, PathRef(classesDir)))
} catch {
case e: CompileFailed =>
Result.Failure(e.toString)
Expand Down

0 comments on commit 95c2ea2

Please sign in to comment.