Benchmarked against https://github.com/tanishiking/scala-js/tree/opt%2Btyped-closures that contains the following changes.
- CI ONLY Enable the optimizer with WebAssembly. by sjrd · Pull Request #4993 · scala-js/scala-js
- RFC: Introduce TypedClosures in the IR, which are closures without JS interop. by sjrd · Pull Request #5003 · scala-js/scala-js
The benchmark is
- https://github.com/sjrd/scalajs-benchmarks/commits/wasm/
- https://github.com/sjrd/scalajs-benchmarks/commit/6bc8ad791076117c14c9b82d3d2cdd00cb69cb00
with the following changes
diff --git a/build.sbt b/build.sbt
index 2e3f9aa..6f5d281 100644
--- a/build.sbt
+++ b/build.sbt
@@ -22,6 +22,18 @@ ThisBuild / scalaJSLinkerConfig ~= { prev =>
.withSemantics(_.optimized)
.withModuleKind(ModuleKind.ESModule)
.withOutputPatterns(OutputPatterns.fromJSFile("%s.mjs"))
+ .withExperimentalUseWebAssembly(false)
+ .withOptimizer(true)
+ .withSemantics { sems =>
+ sems
+ .withAsInstanceOfs(Unchecked)
+ .withArrayIndexOutOfBounds(Unchecked)
+ .withArrayStores(Unchecked)
+ .withNegativeArraySizes(Unchecked)
+ .withNullPointers(Unchecked)
+ .withStringIndexOutOfBounds(Unchecked)
+ .withModuleInit(Unchecked)
+ }
}
ThisBuild / jsEnv := {
@@ -35,7 +47,7 @@ val defaultSettings: Seq[Setting[_]] = projectSettings ++ Seq(
"-unchecked",
"-feature",
"-encoding", "utf8"
- )
+ ),
)
def envInfo(compiler: String, esVersion: String,
diff --git a/common/js/src/main/scala/org/scalajs/benchmark/Benchmark.scala b/common/js/src/main/scala/org/scalajs/benchmark/Benchmark.scala
index 20c34ca..cd20cd6 100644
--- a/common/js/src/main/scala/org/scalajs/benchmark/Benchmark.scala
+++ b/common/js/src/main/scala/org/scalajs/benchmark/Benchmark.scala
@@ -123,11 +123,14 @@ abstract class Benchmark {
/** Run the benchmark the specified number of milliseconds and return
* the mean execution time and SEM in microseconds.
*/
- def runBenchmark(timeMinimum: Long, runsMinimum: Int): (Double, Double) = {
- if (scala.scalajs.runtime.linkingInfo.isWebAssembly)
- runBenchmarkWasm(timeMinimum, runsMinimum)
- else
- runBenchmarkJS(timeMinimum, runsMinimum)
+ def runBenchmark(timeMinimum: Long, runsMinimum: Int): (Double, Double, String) = {
+ if (scala.scalajs.runtime.linkingInfo.isWebAssembly) {
+ val res = runBenchmarkWasm(timeMinimum, runsMinimum)
+ (res._1, res._2, "wasm")
+ } else {
+ val res = runBenchmarkJS(timeMinimum, runsMinimum)
+ (res._1, res._2, "js")
+ }
}
/** Run the benchmark the specified number of milliseconds and return
@@ -215,10 +218,10 @@ abstract class Benchmark {
setUp()
warmUp()
- val (mean, sem) = runBenchmark(3000, 20)
+ val (mean, sem, env) = runBenchmark(3000, 20)
tearDown()
val envInfo = g.ScalaJSBenchEnvInfo.asInstanceOf[String]
- s"$prefix;$envInfo;${Benchmark.userAgent};$mean;$sem"
+ s"$env$prefix;$envInfo;${Benchmark.userAgent};$mean;$sem"
}
}