Skip to content

Commit 5b3bd62

Browse files
authored
Merge pull request #76 from lucidsoftware/speed-up-zincrunner
Speed up ZincRunner
2 parents d9e701d + 4f8c6d1 commit 5b3bd62

File tree

4 files changed

+25
-22
lines changed

4 files changed

+25
-22
lines changed

rules/private/phases/phase_zinc_compile.bzl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ load(
1919
def phase_zinc_compile(ctx, g):
2020
toolchain = ctx.toolchains["//rules/scala:toolchain_type"]
2121
analysis_store = ctx.actions.declare_file("{}/analysis_store.gz".format(ctx.label.name))
22-
analysis_store_text = ctx.actions.declare_file("{}/analysis_store.text.gz".format(ctx.label.name))
2322
mains_file = ctx.actions.declare_file("{}.jar.mains.txt".format(ctx.label.name))
2423
used = ctx.actions.declare_file("{}/deps_used.txt".format(ctx.label.name))
2524
tmp = ctx.actions.declare_directory("{}/tmp".format(ctx.label.name))
@@ -77,7 +76,6 @@ def phase_zinc_compile(ctx, g):
7776
g.classpaths.jar,
7877
mains_file,
7978
analysis_store,
80-
analysis_store_text,
8179
used,
8280
tmp,
8381
] + g.semanticdb.outputs

src/main/scala/higherkindness/rules_scala/workers/common/CommonArguments.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class CommonArguments private (
1717
val analyses: List[Analysis],
1818
val compilerBridge: Path,
1919
val compilerClasspath: List[Path],
20-
val compilerOptions: List[String],
20+
val compilerOptions: Array[String],
2121

2222
/**
2323
* With [[https://bazel.build/remote/multiplex#multiplex_sandboxing multiplex sandboxing]], Bazel generates a separate
@@ -32,7 +32,7 @@ class CommonArguments private (
3232
val compilerOptionsReferencingPaths: List[String],
3333
val classpath: List[Path],
3434
val debug: Boolean,
35-
val javaCompilerOptions: List[String],
35+
val javaCompilerOptions: Array[String],
3636
val label: String,
3737
val logLevel: LogLevel,
3838
val mainManifest: Path,
@@ -215,8 +215,8 @@ object CommonArguments {
215215
compilerBridge = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("compiler_bridge")),
216216
compilerClasspath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("compiler_classpath")),
217217
compilerOptions = Option(namespace.getList[String]("compiler_option"))
218-
.map(_.asScala.toList)
219-
.getOrElse(List.empty),
218+
.map(_.asScala.toArray)
219+
.getOrElse(Array.empty),
220220
compilerOptionsReferencingPaths = adjustCompilerOptions(
221221
workDir,
222222
Option(namespace.getList[String]("compiler_option_referencing_path"))
@@ -225,7 +225,7 @@ object CommonArguments {
225225
),
226226
classpath = SandboxUtil.getSandboxPaths(workDir, namespace.getList[Path]("classpath")),
227227
debug = namespace.getBoolean("debug"),
228-
javaCompilerOptions = namespace.getList[String]("java_compiler_option").asScala.toList,
228+
javaCompilerOptions = namespace.getList[String]("java_compiler_option").asScala.toArray,
229229
label = namespace.getString("label"),
230230
logLevel = LogLevel(namespace.getString("log_level")),
231231
mainManifest = SandboxUtil.getSandboxPath(workDir, namespace.get[Path]("main_manifest")),

src/main/scala/higherkindness/rules_scala/workers/zinc/compile/ZincRunner.scala

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,14 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] {
209209

210210
val compileOptions =
211211
CompileOptions.create
212-
.withSources(sources.map(source => PlainVirtualFile(source.toAbsolutePath().normalize())).toArray)
213-
.withClasspath((classesOutputDir +: deps.map(_.classpath)).map(path => PlainVirtualFile(path)).toArray)
212+
.withSources(sources.view.map(source => PlainVirtualFile(source.toAbsolutePath().normalize())).toArray)
213+
.withClasspath((classesOutputDir +: deps.view.map(_.classpath)).map(path => PlainVirtualFile(path)).toArray)
214214
.withClassesDirectory(classesOutputDir)
215-
.withJavacOptions(workRequest.javaCompilerOptions.toArray)
215+
.withJavacOptions(workRequest.javaCompilerOptions)
216216
.withScalacOptions(
217-
(
218-
workRequest.plugins.map(p => s"-Xplugin:$p") ++
219-
workRequest.compilerOptions ++
220-
workRequest.compilerOptionsReferencingPaths
221-
).toArray,
217+
workRequest.plugins.view.map(p => s"-Xplugin:$p").toArray ++
218+
workRequest.compilerOptions ++
219+
workRequest.compilerOptionsReferencingPaths.toArray,
222220
)
223221

224222
val compilers = {
@@ -304,11 +302,6 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] {
304302

305303
// create analyses
306304
val pathString = analysisStorePath.toAbsolutePath().normalize().toString()
307-
val analysisStoreText = AnalysisUtil.getAnalysisStore(
308-
new File(pathString.substring(0, pathString.length() - 3) + ".text.gz"),
309-
true,
310-
readWriteMappers,
311-
)
312305
// Filter out libraryClassNames from the analysis because it is non-deterministic.
313306
// Can stop doing this once the bug in Zinc is fixed. Check the comment on FilteredRelations
314307
// for more info.
@@ -319,7 +312,18 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] {
319312
infos = FilteredInfos.getFilteredInfos(originalResultAnalysis.infos),
320313
)
321314
}
322-
analysisStoreText.set(AnalysisContents.create(resultAnalysis, compileResult.setup))
315+
316+
// This will be true if the `--worker_verbose` Bazel flag is set
317+
if (verbosity >= 10) {
318+
val analysisStoreText = AnalysisUtil.getAnalysisStore(
319+
new File(pathString.substring(0, pathString.length() - 3) + ".text.gz"),
320+
true,
321+
readWriteMappers,
322+
)
323+
324+
analysisStoreText.set(AnalysisContents.create(resultAnalysis, compileResult.setup))
325+
}
326+
323327
analysisStore.set(AnalysisContents.create(resultAnalysis, compileResult.setup))
324328

325329
// create used deps
@@ -329,7 +333,7 @@ object ZincRunner extends WorkerMain[ZincRunnerWorkerConfig] {
329333
deps.filter(Dep.used(deps, resultAnalysis.relations, lookup)).filterNot { dep =>
330334
val filteredDepFileName = FileUtil.getNameWithoutRulesJvmExternalStampPrefix(dep.file)
331335

332-
scalaInstance.libraryJars
336+
scalaInstance.libraryJars.view
333337
.map(FileUtil.getNameWithoutRulesJvmExternalStampPrefix)
334338
.contains(filteredDepFileName)
335339
}

tests/.bazelversion

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.4.1

0 commit comments

Comments
 (0)