Remove unnecessary `SkyQueryEnvironment#configureEvaluationContext` and `EvaluationContext#getCopyWithKeepGoing` methods.
For the former, use inheritance.
For the latter, simply implement it manually. The `return this` optimization is unnecessary; this code is called exactly once per SkyQuery `blaze query` invocation, so we're saving a few ns of wall time at most.
PiperOrigin-RevId: 417844698
diff --git a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
index 265c4b3..8806457 100644
--- a/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
+++ b/src/main/java/com/google/devtools/build/lib/query2/SkyQueryEnvironment.java
@@ -248,6 +248,13 @@
return ImmutableSet.of(universeKey);
}
+ protected EvaluationContext newEvaluationContext() {
+ return EvaluationContext.newBuilder()
+ .setNumThreads(loadingPhaseThreads)
+ .setEventHandler(universeEvalEventHandler)
+ .build();
+ }
+
protected void beforeEvaluateQuery(QueryExpression expr)
throws QueryException, InterruptedException {
UniverseSkyKey universeKey = universeScope.getUniverseKey(expr, parserPrefix);
@@ -257,12 +264,7 @@
EvaluationResult<SkyValue> result;
try (AutoProfiler p = GoogleAutoProfilerUtils.logged("evaluation and walkable graph")) {
- EvaluationContext evaluationContext =
- EvaluationContext.newBuilder()
- .setNumThreads(loadingPhaseThreads)
- .setEventHandler(universeEvalEventHandler)
- .build();
- result = graphFactory.prepareAndGet(roots, configureEvaluationContext(evaluationContext));
+ result = graphFactory.prepareAndGet(roots, newEvaluationContext());
}
if (graph == null || graph != result.getWalkableGraph()) {
@@ -311,14 +313,6 @@
TargetPatternKey::getParsedPattern));
}
- /**
- * Configures the default {@link EvaluationContext} to change the behavior of how evaluations in
- * {@link WalkableGraphFactory#prepareAndGet} work.
- */
- protected EvaluationContext configureEvaluationContext(EvaluationContext evaluationContext) {
- return evaluationContext;
- }
-
protected MultisetSemaphore<PackageIdentifier> makeFreshPackageMultisetSemaphore() {
return MultisetSemaphore.unbounded();
}
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
index dd0c55d..a80db3d 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java
@@ -2526,9 +2526,11 @@
* a complete graph to work on.
*/
@Override
- public EvaluationResult<SkyValue> prepareAndGet(
+ public final EvaluationResult<SkyValue> prepareAndGet(
Set<SkyKey> roots, EvaluationContext evaluationContext) throws InterruptedException {
- return buildDriver.evaluate(roots, evaluationContext.getCopyWithKeepGoing(/*keepGoing=*/ true));
+ EvaluationContext evaluationContextToUse =
+ evaluationContext.builder().setKeepGoing(/*keepGoing=*/ true).build();
+ return buildDriver.evaluate(roots, evaluationContextToUse);
}
/**
diff --git a/src/main/java/com/google/devtools/build/skyframe/EvaluationContext.java b/src/main/java/com/google/devtools/build/skyframe/EvaluationContext.java
index 022c1bf..ddb586c 100644
--- a/src/main/java/com/google/devtools/build/skyframe/EvaluationContext.java
+++ b/src/main/java/com/google/devtools/build/skyframe/EvaluationContext.java
@@ -72,22 +72,6 @@
return eventHandler;
}
- public EvaluationContext getCopyWithKeepGoing(boolean keepGoing) {
- if (this.keepGoing == keepGoing) {
- return this;
- } else {
- return new EvaluationContext(
- this.numThreads,
- this.executorServiceSupplier,
- keepGoing,
- this.eventHandler,
- this.useForkJoinPool,
- this.isExecutionPhase,
- this.cpuHeavySkyKeysThreadPoolSize,
- this.executionPhaseThreadPoolSize);
- }
- }
-
public boolean getUseForkJoinPool() {
return useForkJoinPool;
}
@@ -118,24 +102,28 @@
return isExecutionPhase;
}
+ public Builder builder() {
+ return newBuilder().copyFrom(this);
+ }
+
public static Builder newBuilder() {
return new Builder();
}
/** Builder for {@link EvaluationContext}. */
public static class Builder {
- private int numThreads;
- private Supplier<ExecutorService> executorServiceSupplier;
- private boolean keepGoing;
- private ExtendedEventHandler eventHandler;
- private boolean useForkJoinPool;
- private int cpuHeavySkyKeysThreadPoolSize;
- private int executionJobsThreadPoolSize = 0;
- private boolean isExecutionPhase = false;
+ protected int numThreads;
+ protected Supplier<ExecutorService> executorServiceSupplier;
+ protected boolean keepGoing;
+ protected ExtendedEventHandler eventHandler;
+ protected boolean useForkJoinPool;
+ protected int cpuHeavySkyKeysThreadPoolSize;
+ protected int executionJobsThreadPoolSize = 0;
+ protected boolean isExecutionPhase = false;
- private Builder() {}
+ protected Builder() {}
- public Builder copyFrom(EvaluationContext evaluationContext) {
+ protected Builder copyFrom(EvaluationContext evaluationContext) {
this.numThreads = evaluationContext.numThreads;
this.executorServiceSupplier = evaluationContext.executorServiceSupplier;
this.keepGoing = evaluationContext.keepGoing;
@@ -183,7 +171,7 @@
}
public Builder setExecutionPhase() {
- isExecutionPhase = true;
+ this.isExecutionPhase = true;
return this;
}
diff --git a/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java b/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java
index 188743a..bc459de 100644
--- a/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java
+++ b/src/main/java/com/google/devtools/build/skyframe/SequentialBuildDriver.java
@@ -40,8 +40,8 @@
curVersion,
evaluationContext.getExecutorServiceSupplier().isPresent()
? evaluationContext
- : EvaluationContext.newBuilder()
- .copyFrom(evaluationContext)
+ : evaluationContext
+ .builder()
.setNumThreads(evaluationContext.getParallelism())
.setExecutorServiceSupplier(
() ->