Skip to content

Commit 4ccfda1

Browse files
committed
Make SBT based benchmarking more flexible
- Allow injection of extra settings in to the build - Parameterize the command name used to compile. - Create a custom "compileRaw" task in the build (for SBT 0.13.x, the API I'm using must have shifted in 1.0.x) Testing a local build of SBT that disables its metadata collection compiler phases when `antStyle = true`. ``` sbt> set scalaVersion in compilation := "2.12.3-bin-d1ec01a-SNAPSHOT" sbt> compilation/jmh:run HotSbtBenchmark -psource=scalap -psbtVersion=0.13.16-bin-7b5d818 -pextraBuild=incOptions:=incOptions.value.withNameHashing(false).withAntStyle(true) ... [info] Benchmark (compileCmd) (corpusVersion) (extraArgs) (extraBuild) (sbtVersion) (source) Mode Cnt Score Error Units [info] HotSbtBenchmark.compile a8c43dc incOptions:=incOptions.value.withNameHashing(false).withAntStyle(true) 0.13.16-bin-7b5d818 scalap sample 330 956.082 ± 7.116 ms/op ``` Bypassing the `compile` task altogether in favour of user of SBT's `RawCompiler`. ``` sbt> compilation/jmh:run HotSbtBenchmark -psource=scalap -psbtVersion=0.13.15 -pcompileCmd=compileRaw [info] Benchmark (compileCmd) (corpusVersion) (extraArgs) (extraBuild) (sbtVersion) (source) Mode Cnt Score Error Units [info] HotSbtBenchmark.compile compileRaw a8c43dc 0.13.15 scalap sample 357 888.775 ± 7.243 ms/op ``` The base and top-lines that we're comparing against: - `HotScalacBenchmark` for the same Scala revision: 765ms. - `HotSbtBenchmark` using default config and compile task from 0.13.15: 1063ms Discussion: - The overhead of the terminal scraping between the JMH benchmark process and the child SBT process might be a factor here. Try a larger codebases to reduce that effect. - The SBT compiler phases appear to levy only ~12% overhead, which seems quite reasonable. - We need to find out what other factors are preventing the results above from coming in closer to the direct compiler usage.
1 parent b495678 commit 4ccfda1

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

compilation/src/main/scala/scala/tools/nsc/HotSbtBenchmark.scala

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class HotSbtBenchmark {
2828
@Param(value = Array("0.13.15"))
2929
var sbtVersion: String = _
3030

31+
@Param(value = Array(""))
32+
var extraBuild: String = _
33+
34+
@Param(value= Array("compile"))
35+
var compileCmd: String = _
36+
3137
// This parameter is set by ScalacBenchmarkRunner / UploadingRunner based on the Scala version.
3238
// When running the benchmark directly the "latest" symlink is used.
3339
@Param(value = Array("latest"))
@@ -42,6 +48,19 @@ class HotSbtBenchmark {
4248
var processInputReader: BufferedWriter = _
4349
var output= new java.lang.StringBuilder()
4450

51+
def compileRawSetting = if (sbtVersion.startsWith("1.")) "" else
52+
"""
53+
|val compileRaw = taskKey[Unit]("Compile directly, bypassing the incremental compiler")
54+
|
55+
|def addCompileRaw = compileRaw := {
56+
| val compiler = new sbt.compiler.RawCompiler(scalaInstance.value, sbt.ClasspathOptions.auto, streams.value.log)
57+
| classDirectory.value.mkdirs()
58+
| compiler.apply(sources.value, classDirectory.value +: dependencyClasspath.value.map(_.data), classDirectory.value, scalacOptions.value)
59+
| }
60+
|
61+
|inConfig(Compile)(List(addCompileRaw))
62+
""".stripMargin
63+
4564
def buildDef =
4665
s"""
4766
|scalaHome := Some(file("${scalaHome.toAbsolutePath.toString}"))
@@ -55,6 +74,12 @@ class HotSbtBenchmark {
5574
|libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
5675
|libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
5776
|
77+
|traceLevel := Int.MaxValue
78+
|traceLevel in runMain := Int.MaxValue
79+
|
80+
|$compileRawSetting
81+
|
82+
|$extraBuild
5883
|// TODO support .java sources
5984
""".stripMargin
6085

@@ -79,7 +104,7 @@ class HotSbtBenchmark {
79104

80105
@Benchmark
81106
def compile(): Unit = {
82-
issue(";cleanClasses;compile")
107+
issue(s";cleanClasses;$compileCmd")
83108
awaitPrompt()
84109
}
85110

0 commit comments

Comments
 (0)