-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a microbenchmark for type inference / dataflow (#617)
This will help us to identify performance issues in our dataflow analysis that could improve NullAway's performance on large methods. The benchmark was generated with a script.
- Loading branch information
Showing
6 changed files
with
684 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
jmh/src/jmh/java/com/uber/nullaway/jmh/DFlowMicroBenchmark.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.uber.nullaway.jmh; | ||
|
||
import java.io.IOException; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Scope; | ||
import org.openjdk.jmh.annotations.Setup; | ||
import org.openjdk.jmh.annotations.State; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
|
||
@State(Scope.Benchmark) | ||
public class DFlowMicroBenchmark { | ||
|
||
private DataFlowMicroBenchmarkCompiler compiler; | ||
|
||
@Setup | ||
public void setup() throws IOException { | ||
compiler = new DataFlowMicroBenchmarkCompiler(); | ||
} | ||
|
||
@Benchmark | ||
public void compile(Blackhole bh) { | ||
bh.consume(compiler.compile()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
jmh/src/main/java/com/uber/nullaway/jmh/DataFlowMicroBenchmarkCompiler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.uber.nullaway.jmh; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class DataFlowMicroBenchmarkCompiler { | ||
|
||
private final NullawayJavac nullawayJavac; | ||
|
||
public DataFlowMicroBenchmarkCompiler() throws IOException { | ||
nullawayJavac = NullawayJavac.createFromSourceString("DFlowBench", SOURCE, "com.uber"); | ||
} | ||
|
||
public boolean compile() { | ||
return nullawayJavac.compile(); | ||
} | ||
|
||
private static final String SOURCE; | ||
|
||
static { | ||
// For larger benchmarks, we pass file paths to NullawayJavac, based on JVM properties computed | ||
// in build.gradle. Here, to avoid creating and passing yet another JVM property, we just store | ||
// the benchmark source code in a resource file and then load it eagerly into a String via the | ||
// classloader | ||
ClassLoader classLoader = DataFlowMicroBenchmarkCompiler.class.getClassLoader(); | ||
try (InputStream inputStream = classLoader.getResourceAsStream("DFlowBench.java")) { | ||
SOURCE = readFromInputStream(inputStream); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private static String readFromInputStream(InputStream inputStream) throws IOException { | ||
StringBuilder result = new StringBuilder(); | ||
try (BufferedReader br = | ||
new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { | ||
String line; | ||
while ((line = br.readLine()) != null) { | ||
result.append(line).append("\n"); | ||
} | ||
} | ||
return result.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.