From 5efa0ff1bf6ed76e7e723e679769afd27a433e27 Mon Sep 17 00:00:00 2001 From: Anton Sviridov Date: Wed, 26 Jul 2023 15:03:22 +0100 Subject: [PATCH] Run sample benchmarks on CI (#622) * Remove LSIF-related benchmarks --- .github/workflows/ci.yml | 13 +++++++++++++ .../src/main/scala/benchmarks/CompileBench.scala | 14 +++++++++----- .../scala/benchmarks/ScipSemanticdbBench.scala | 10 ---------- .../unit/src/main/scala/tests/CompileResult.scala | 6 ++++-- .../unit/src/test/scala/tests/OverridesSuite.scala | 2 +- .../unit/src/test/scala/tests/TargetedSuite.scala | 5 +++-- 6 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 01e2bf21e..bafee376d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,19 @@ jobs: - name: Main project tests run: sbt test + benchmarks-test: + runs-on: ubuntu-latest + name: Benchmark tests + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-java@v3 + with: + distribution: "temurin" + cache: "sbt" + java-version: 17 + - name: Run sample benchmarks + run: sbt 'bench/Jmh/run -i 1 -f1 -t1 -foe true' + docker_test: runs-on: ${{ matrix.os }} name: Docker CLI tests diff --git a/tests/benchmarks/src/main/scala/benchmarks/CompileBench.scala b/tests/benchmarks/src/main/scala/benchmarks/CompileBench.scala index 00264ca0a..713c161e2 100644 --- a/tests/benchmarks/src/main/scala/benchmarks/CompileBench.scala +++ b/tests/benchmarks/src/main/scala/benchmarks/CompileBench.scala @@ -62,7 +62,11 @@ class CompileBench { @OutputTimeUnit(TimeUnit.MILLISECONDS) def compileSemanticdb(): Long = { CompileBench.foreachSource(deps) { inputs => - compiler.compileSemanticdb(inputs).textDocument.getOccurrencesCount + compiler + .compileSemanticdb(inputs) + .textDocument + .map(_.getOccurrencesCount) + .getOrElse(0) } } @@ -74,10 +78,9 @@ object CompileBench { def foreachSource( deps: Dependencies )(fn: Seq[Input.VirtualFile] => Int): Long = { - var sum = 0L deps .sources - .foreach { source => + .map { source => val path = AbsolutePath(source) FileIO.withJarFileSystem(path, create = false, close = true) { root => val files = @@ -91,9 +94,10 @@ object CompileBench { val relativePath = source.toString().stripPrefix("/") Input.VirtualFile(relativePath, text) } - sum += fn(inputs) + + fn(inputs) } } - sum + .sum } } diff --git a/tests/benchmarks/src/main/scala/benchmarks/ScipSemanticdbBench.scala b/tests/benchmarks/src/main/scala/benchmarks/ScipSemanticdbBench.scala index df37874ab..86d6f8dc9 100644 --- a/tests/benchmarks/src/main/scala/benchmarks/ScipSemanticdbBench.scala +++ b/tests/benchmarks/src/main/scala/benchmarks/ScipSemanticdbBench.scala @@ -48,16 +48,6 @@ class ScipSemanticdbBench { @OutputTimeUnit(TimeUnit.MILLISECONDS) def json(): Unit = run("index.scip", parallel = false) - @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime)) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - def protobufParallel(): Unit = run("index.scip-protobuf", parallel = true) - - @Benchmark - @BenchmarkMode(Array(Mode.SingleShotTime)) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - def protobuf(): Unit = run("index.scip-protobuf", parallel = false) - private def run(filename: String, parallel: Boolean): Unit = { val output = Files.createTempFile("scip-java", filename) val parallelFlag = diff --git a/tests/unit/src/main/scala/tests/CompileResult.scala b/tests/unit/src/main/scala/tests/CompileResult.scala index 108cbf130..5c582337f 100644 --- a/tests/unit/src/main/scala/tests/CompileResult.scala +++ b/tests/unit/src/main/scala/tests/CompileResult.scala @@ -8,8 +8,10 @@ case class CompileResult( textDocuments: Semanticdb.TextDocuments, isSuccess: Boolean ) { - def textDocument: Semanticdb.TextDocument = { - textDocuments.getDocuments(0) + def textDocument: Option[Semanticdb.TextDocument] = { + Option.when(textDocuments.getDocumentsCount() > 0) { + textDocuments.getDocuments(0) + } } def merge(other: CompileResult): CompileResult = { diff --git a/tests/unit/src/test/scala/tests/OverridesSuite.scala b/tests/unit/src/test/scala/tests/OverridesSuite.scala index daa732eef..4aff5d18c 100644 --- a/tests/unit/src/test/scala/tests/OverridesSuite.scala +++ b/tests/unit/src/test/scala/tests/OverridesSuite.scala @@ -26,7 +26,7 @@ class OverridesSuite extends FunSuite with TempDirectories { val relativePath = "example.Parent".replace('.', '/') + ".java" val input = Input.VirtualFile(relativePath, source) val result = compiler.compileSemanticdb(List(input)) - val symtab = new Symtab(result.textDocument) + val symtab = new Symtab(result.textDocument.orNull) val expectedSyms = expectedSymbols.mkString("\n") val syms = symtab diff --git a/tests/unit/src/test/scala/tests/TargetedSuite.scala b/tests/unit/src/test/scala/tests/TargetedSuite.scala index eb19edf70..0b554c917 100644 --- a/tests/unit/src/test/scala/tests/TargetedSuite.scala +++ b/tests/unit/src/test/scala/tests/TargetedSuite.scala @@ -44,7 +44,8 @@ class TargetedSuite extends FunSuite with TempDirectories { }) .toList val result = compiler.compileSemanticdb(List(input)) - val occurrences = result.textDocument.getOccurrencesList.asScala.toList + val textDocument = result.textDocument.orNull + val occurrences = textDocument.getOccurrencesList.asScala.toList val symbols: List[String] = positions.map { pos => val posRange = Semanticdb .Range @@ -74,7 +75,7 @@ class TargetedSuite extends FunSuite with TempDirectories { ) } } - fn(result.textDocument, symbols) + fn(textDocument, symbols) } }