forked from jenkinsci/jenkins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimize Label parsing calls (jenkinsci#8395)
* Optimize Label#parse for simple label For a simple label, this speeds up lookup of an existing simple label (no expression used): 16ns vs 106ns (6x faster) * Fix reviews * Fix include * Avoid parsing label every time getAssignedLabels is called * Store Set<LabelAtom> at Node descendants level * Compute it whenever labelString is updated * Fix spotbugs / test issue * Make it restricted
- Loading branch information
1 parent
c8c0cf3
commit 6ea5a73
Showing
5 changed files
with
156 additions
and
9 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
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
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
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
82 changes: 82 additions & 0 deletions
82
test/src/test/java/hudson/model/labels/LabelBenchmarkTest.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,82 @@ | ||
package hudson.model.labels; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
import hudson.model.Label; | ||
import hudson.slaves.DumbSlave; | ||
import hudson.slaves.JNLPLauncher; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.concurrent.TimeUnit; | ||
import jenkins.benchmark.jmh.JmhBenchmark; | ||
import jenkins.benchmark.jmh.JmhBenchmarkState; | ||
import org.junit.Test; | ||
import org.openjdk.jmh.annotations.Benchmark; | ||
import org.openjdk.jmh.annotations.Mode; | ||
import org.openjdk.jmh.infra.Blackhole; | ||
import org.openjdk.jmh.results.format.ResultFormatType; | ||
import org.openjdk.jmh.runner.Runner; | ||
import org.openjdk.jmh.runner.options.ChainedOptionsBuilder; | ||
import org.openjdk.jmh.runner.options.OptionsBuilder; | ||
|
||
public class LabelBenchmarkTest { | ||
@Test | ||
public void runBenchmark() throws Exception { | ||
// run the minimum possible number of iterations | ||
ChainedOptionsBuilder options = new OptionsBuilder() | ||
.mode(Mode.AverageTime) | ||
.forks(1) | ||
.result("jmh-report.json") | ||
.resultFormat(ResultFormatType.JSON) | ||
.operationsPerInvocation(1) | ||
.threads(1) | ||
.warmupForks(0) | ||
.warmupIterations(0) | ||
.measurementBatchSize(1) | ||
.measurementIterations(1) | ||
.timeUnit(TimeUnit.NANOSECONDS) | ||
.shouldFailOnError(true) | ||
.include(LabelBenchmarkTest.class.getName() + ".*"); | ||
new Runner(options.build()).run(); | ||
assertTrue(Files.exists(Paths.get("jmh-report.json"))); | ||
} | ||
|
||
@JmhBenchmark | ||
public static class NodeLabelBenchmark { | ||
public static class StateImpl extends JmhBenchmarkState { | ||
@Override | ||
public void setup() throws Exception { | ||
DumbSlave test = new DumbSlave("test", "/tmp/slave", new JNLPLauncher()); | ||
test.setLabelString("a b c"); | ||
getJenkins().addNode(test); | ||
} | ||
} | ||
|
||
@Benchmark | ||
public void nodeGetAssignedLabels(StateImpl state, Blackhole blackhole) { | ||
blackhole.consume(state.getJenkins().getNode("test").getAssignedLabels()); | ||
} | ||
} | ||
|
||
|
||
@JmhBenchmark | ||
public static class LabelBenchmark { | ||
public static class MyState extends JmhBenchmarkState { | ||
} | ||
|
||
@Benchmark | ||
public void simpleLabel(MyState state, Blackhole blackhole) { | ||
blackhole.consume(Label.parse("some-label")); | ||
} | ||
|
||
@Benchmark | ||
public void complexLabel(MyState state, Blackhole blackhole) { | ||
blackhole.consume(Label.parse("label1 && label2")); | ||
} | ||
|
||
@Benchmark | ||
public void jenkinsGetAssignedLabels(MyState state, Blackhole blackhole) { | ||
blackhole.consume(state.getJenkins().getAssignedLabels()); | ||
} | ||
} | ||
} |