diff options
author | George Fraser <george@fivetran.com> | 2019-01-01 20:51:24 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2019-01-01 20:51:24 -0800 |
commit | b398d1ca3643a6e58aa83c7df98312e538c966c0 (patch) | |
tree | 021cdaab4c8ed9416904776b3ab11e450f5f7690 /src/test/java | |
parent | f3faf409445e82cfa12f9993c4075a5523000c0e (diff) | |
download | java-language-server-b398d1ca3643a6e58aa83c7df98312e538c966c0.zip |
Error-prone is too slow
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/javacs/ErrorProneBenchmark.java | 96 | ||||
-rw-r--r-- | src/test/java/org/javacs/JavaCompilerServiceTest.java | 7 | ||||
-rw-r--r-- | src/test/java/org/javacs/StringSearchBenchmark.java | 44 |
3 files changed, 123 insertions, 24 deletions
diff --git a/src/test/java/org/javacs/ErrorProneBenchmark.java b/src/test/java/org/javacs/ErrorProneBenchmark.java new file mode 100644 index 0000000..6e0b7ba --- /dev/null +++ b/src/test/java/org/javacs/ErrorProneBenchmark.java @@ -0,0 +1,96 @@ +package org.javacs; + +import com.sun.source.util.JavacTask; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.ServiceLoader; +import java.util.Set; +import java.util.StringJoiner; +import java.util.concurrent.TimeUnit; +import javax.tools.JavaCompiler; +import javax.tools.StandardJavaFileManager; +import org.openjdk.jmh.annotations.*; + +// TODO this is coloring badly +@Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) +@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) +@Fork(1) +public class ErrorProneBenchmark { + private static Path file = Paths.get(FindResource.uri("/org/javacs/example/BenchmarkStringSearch.java")); + + @State(Scope.Thread) + public static class BenchmarkState { + JavaCompiler compiler = ServiceLoader.load(JavaCompiler.class).iterator().next(); + StandardJavaFileManager fileManager = + new FileManagerWrapper(compiler.getStandardFileManager(__ -> {}, null, Charset.defaultCharset())); + } + + @Benchmark + public void vanilla(BenchmarkState state) { + var options = JavaCompilerService.options(Set.of(), Set.of()); + + analyze(state, options); + } + + @Benchmark + public void withErrorProne(BenchmarkState state) { + var options = JavaCompilerService.options(Set.of(), Set.of()); + // Add error-prone + options.addAll(errorProneOptions()); + + analyze(state, options); + } + + private void analyze(BenchmarkState state, List<String> options) { + var sources = state.fileManager.getJavaFileObjectsFromPaths(List.of(file)); + // Create task + var task = + (JavacTask) + state.compiler.getTask( + null, state.fileManager, __ -> {}, options, Collections.emptyList(), sources); + // Print timing information for optimization + var profiler = new Profiler(); + try { + task.analyze(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static List<String> errorProneOptions() { + var options = new ArrayList<String>(); + + // https://errorprone.info/docs/installation "Command Line" + Collections.addAll(options, "-XDcompilePolicy=byfile"); + Collections.addAll(options, "-processorpath", Lib.ERROR_PRONE); + + // https://errorprone.info/bugpatterns + var bugPatterns = new StringJoiner(" "); + // bugPatterns.add("-Xep:EmptyIf"); + // bugPatterns.add("-Xep:NumericEquality"); + // bugPatterns.add("-Xep:ConstructorLeaksThis"); + // bugPatterns.add("-Xep:EqualsBrokenForNull"); + // bugPatterns.add("-Xep:InvalidThrows"); + // bugPatterns.add("-Xep:RedundantThrows"); + // bugPatterns.add("-Xep:StaticQualifiedUsingExpression"); + // bugPatterns.add("-Xep:StringEquality"); + // bugPatterns.add("-Xep:Unused"); + // bugPatterns.add("-Xep:UnusedException"); + // bugPatterns.add("-Xep:FieldCanBeFinal"); + // bugPatterns.add("-Xep:FieldMissingNullable"); + // bugPatterns.add("-Xep:MethodCanBeStatic"); + // bugPatterns.add("-Xep:PackageLocation"); + // bugPatterns.add("-Xep:PrivateConstructorForUtilityClass"); + // bugPatterns.add("-Xep:ReturnMissingNullable"); + + Collections.addAll( + options, "-Xplugin:ErrorProne -XepAllErrorsAsWarnings " + bugPatterns + " --illegal-access=warn"); + + return options; + } +} diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java index e06e72a..0785acb 100644 --- a/src/test/java/org/javacs/JavaCompilerServiceTest.java +++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java @@ -18,6 +18,7 @@ import java.util.stream.Collectors; import javax.lang.model.element.Element; import javax.tools.Diagnostic; import javax.tools.JavaFileObject; +import org.junit.Ignore; import org.junit.Test; public class JavaCompilerServiceTest { @@ -300,10 +301,10 @@ public class JavaCompilerServiceTest { return strings; } + // TODO get these back somehow @Test + @Ignore public void errorProne() { - // TODO verify that error-prone *only* runs when you call reportErrors(), - // by calling compileFile() and checking no diagnostic is reported var uri = resourceUri("ErrorProne.java"); var files = Collections.singleton(uri); var diags = compiler.reportErrors(files); @@ -311,7 +312,9 @@ public class JavaCompilerServiceTest { assertThat(strings, hasItem(containsString("ErrorProne.java(7): [CollectionIncompatibleType]"))); } + // TODO get these back somehow @Test + @Ignore public void unusedVar() { var uri = resourceUri("UnusedVar.java"); var files = Collections.singleton(uri); diff --git a/src/test/java/org/javacs/StringSearchBenchmark.java b/src/test/java/org/javacs/StringSearchBenchmark.java index 92abbbf..e044812 100644 --- a/src/test/java/org/javacs/StringSearchBenchmark.java +++ b/src/test/java/org/javacs/StringSearchBenchmark.java @@ -14,31 +14,31 @@ public class StringSearchBenchmark { smallFile = Paths.get(FindResource.uri("/org/javacs/example/Goto.java")); // "removeMethodBodies" appears late in the file, so stopping early will not be very effective private static final String query = "removeMethodBodies"; - /* - @Benchmark - public void containsWordMatchingSmall() { - var found = Parser.containsWordMatching(smallFile, query); - assert found; - } - @Benchmark - public void containsWordMatchingLarge() { - var found = Parser.containsWordMatching(largeFile, query); - assert found; - } + @Benchmark + public void containsWordMatchingSmall() { + var found = Parser.containsWordMatching(smallFile, query); + assert found; + } + + @Benchmark + public void containsWordMatchingLarge() { + var found = Parser.containsWordMatching(largeFile, query); + assert found; + } - @Benchmark - public void containsTextSmall() { - var found = Parser.containsText(smallFile, query); - assert found; - } + @Benchmark + public void containsTextSmall() { + var found = Parser.containsText(smallFile, query); + assert found; + } + + @Benchmark + public void containsTextLarge() { + var found = Parser.containsText(largeFile, query); + assert found; + } - @Benchmark - public void containsTextLarge() { - var found = Parser.containsText(largeFile, query); - assert found; - } - */ @Benchmark public void containsImportLarge() { var found = JavaCompilerService.containsImport("java.util.nopkg", "Logger", largeFile); |