Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions tests/benchmarks/src/main/scala/benchmarks/CompileBench.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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 =
Expand All @@ -91,9 +94,10 @@ object CompileBench {
val relativePath = source.toString().stripPrefix("/")
Input.VirtualFile(relativePath, text)
}
sum += fn(inputs)

fn(inputs)
}
}
sum
.sum
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/src/main/scala/tests/CompileResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was previously crashing, likely terminating the benchmark prematurely.

[info] <failure>
[info] java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
[info]  at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
[info]  at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
[info]  at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
[info]  at java.base/java.util.Objects.checkIndex(Objects.java:372)
[info]  at java.base/java.util.ArrayList.get(ArrayList.java:459)
[info]  at java.base/java.util.Collections$UnmodifiableList.get(Collections.java:1310)
[info]  at com.sourcegraph.semanticdb_javac.Semanticdb$TextDocuments.getDocuments(Semanticdb.java:669)
[info]  at tests.CompileResult.textDocument(CompileResult.scala:12)
[info]  at benchmarks.CompileBench.$anonfun$compileSemanticdb$1(CompileBench.scala:65)
[info]  at benchmarks.CompileBench.$anonfun$compileSemanticdb$1$adapted(CompileBench.scala:64)
[info]  at benchmarks.CompileBench$.$anonfun$foreachSource$2(CompileBench.scala:94
[info]  at benchmarks.CompileBench$.$anonfun$foreachSource$2$adapted(CompileBench.scala:82)
[info]  at scala.meta.internal.io.PlatformFileIO$.withJarFileSystem(PlatformFileIO.scala:80)
[info]  at scala.meta.internal.io.FileIO$.withJarFileSystem(FileIO.scala:44)
[info]  at benchmarks.CompileBench$.$anonfun$foreachSource$1(CompileBench.scala:82
[info]  at benchmarks.CompileBench$.$anonfun$foreachSource$1$adapted(CompileBench.scala:80)
[info]  at scala.collection.immutable.List.foreach(List.scala:333)
[info]  at benchmarks.CompileBench$.foreachSource(CompileBench.scala:80)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I'd check which dependency causes this:

[info] ArraySeq(edu/umd/cs/findbugs/annotations/When.java, edu/umd/cs/findbugs/annotations/UnknownNullness.java, edu/umd/cs/findbugs/annotations/SuppressWarnings.java, edu/umd/cs/findbugs/annotations/SuppressFBWarnings.java, edu/umd/cs/findbugs/annotations/ReturnValuesAreNonnullByDefault.java, edu/umd/cs/findbugs/annotations/Priority.java, edu/umd/cs/findbugs/annotations/PossiblyNull.java, edu/umd/cs/findbugs/annotations/package-info.java, edu/umd/cs/findbugs/annotations/OverrideMustInvoke.java, edu/umd/cs/findbugs/annotations/Nullable.java, edu/umd/cs/findbugs/annotations/NoWarning.java, edu/umd/cs/findbugs/annotations/NonNull.java, edu/umd/cs/findbugs/annotations/ExpectWarning.java, edu/umd/cs/findbugs/annotations/DischargesObligation.java, edu/umd/cs/findbugs/annotations/DesireWarning.java, edu/umd/cs/findbugs/annotations/DesireNoWarning.java, edu/umd/cs/findbugs/annotations/DefaultAnnotationForParameters.java, edu/umd/cs/findbugs/annotations/DefaultAnnotationForMethods.java, edu/umd/cs/findbugs/annotations/DefaultAnnotationForFields.java, edu/umd/cs/findbugs/annotations/DefaultAnnotation.java, edu/umd/cs/findbugs/annotations/CreatesObligation.java, edu/umd/cs/findbugs/annotations/Confidence.java, edu/umd/cs/findbugs/annotations/CleanupObligation.java, edu/umd/cs/findbugs/annotations/CheckReturnValue.java, edu/umd/cs/findbugs/annotations/CheckForNull.java) returned an empty textDocument

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite strange, because when I index it manually it works:

sbt> cli/run index-dependency --dependency com.google.code.findbugs:jsr305:3.0.2
CleanShot 2023-07-26 at 14 34 52@2x

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, is this a different dependency...

textDocuments.getDocuments(0)
}
}

def merge(other: CompileResult): CompileResult = {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/test/scala/tests/OverridesSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tests/unit/src/test/scala/tests/TargetedSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -74,7 +75,7 @@ class TargetedSuite extends FunSuite with TempDirectories {
)
}
}
fn(result.textDocument, symbols)
fn(textDocument, symbols)
}
}

Expand Down