Skip to content

Commit 71d42f1

Browse files
committed
tighten
1 parent 2e76288 commit 71d42f1

File tree

230 files changed

+2019
-425
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+2019
-425
lines changed

x-pack/plugin/esql/compute/gen/src/main/java/org/elasticsearch/compute/gen/EvaluatorImplementer.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ public EvaluatorImplementer(
7575
this.declarationType = (TypeElement) processFunction.getEnclosingElement();
7676
this.processFunction = new ProcessFunction(elements, types, processFunction, warnExceptions);
7777
this.estimateCost = estimateCost;
78+
if (estimateCost <= 0) {
79+
throw new IllegalArgumentException("estimateCost must be at least 1; got " + estimateCost);
80+
}
7881
this.implementation = ClassName.get(
7982
elements.getPackageOf(declarationType).toString(),
8083
declarationType.getSimpleName() + extraName + "Evaluator"
@@ -197,6 +200,7 @@ private MethodSpec realEval(boolean blockStyle) {
197200
if (vectorize) {
198201
realEvalWithVectorizedStyle(builder, resultDataType);
199202
} else {
203+
builder.addStatement("int accumulatedCost = 0");
200204
builder.beginControlFlow("position: for (int p = 0; p < positionCount; p++)");
201205
{
202206
if (blockStyle) {
@@ -249,8 +253,13 @@ private MethodSpec realEval(boolean blockStyle) {
249253
if (processFunction.warnExceptions.isEmpty() == false) {
250254
builder.beginControlFlow("try");
251255
}
252-
253-
builder.addStatement("driverContext.maybeCheckForEarlyTermination(" + estimateCost + ")");
256+
builder.addStatement("accumulatedCost += " + estimateCost);
257+
builder.beginControlFlow("if (accumulatedCost >= DriverContext.CHECK_FOR_EARLY_TERMINATION_COST_THRESHOLD)");
258+
{
259+
builder.addStatement("accumulatedCost = 0");
260+
builder.addStatement("driverContext.checkForEarlyTermination()");
261+
}
262+
builder.endControlFlow();
254263
builder.addStatement(builtPattern, args.toArray());
255264

256265
if (processFunction.warnExceptions.isEmpty() == false) {
@@ -273,8 +282,8 @@ private MethodSpec realEval(boolean blockStyle) {
273282
}
274283

275284
private void realEvalWithVectorizedStyle(MethodSpec.Builder builder, ClassName resultDataType) {
276-
// generate the tight loop to allow vectorization
277-
builder.addStatement("final int maxBatchSize = DriverContext.estimateBatchSizeForEarlyTermination(" + estimateCost + ")");
285+
builder.addComment("generate a tight loop to allow vectorization");
286+
builder.addStatement("int maxBatchSize = Math.max(DriverContext.CHECK_FOR_EARLY_TERMINATION_COST_THRESHOLD / $L, 1)", estimateCost);
278287
builder.beginControlFlow("for (int start = 0; start < positionCount; )");
279288
{
280289
builder.addStatement("int end = start + Math.min(positionCount - start, maxBatchSize)");

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/DriverContext.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public class DriverContext {
6161
private final WarningsMode warningsMode;
6262

6363
public static final int CHECK_FOR_EARLY_TERMINATION_COST_THRESHOLD = 2048;
64+
private static final Runnable NO_OP = () -> {};
6465
private Runnable earlyTerminationChecker = () -> {};
65-
private int accumulatedCostForEarlyTermination;
6666

6767
public DriverContext(BigArrays bigArrays, BlockFactory blockFactory) {
6868
this(bigArrays, blockFactory, WarningsMode.COLLECT);
@@ -179,21 +179,10 @@ public void removeAsyncAction() {
179179
asyncActions.removeInstance();
180180
}
181181

182-
/**
183-
* Accumulates the early termination cost and runs the early termination check if the accumulated cost passes the threshold.
184-
*/
185-
public void maybeCheckForEarlyTermination(int estimateCost) {
186-
accumulatedCostForEarlyTermination += estimateCost;
187-
if (accumulatedCostForEarlyTermination >= CHECK_FOR_EARLY_TERMINATION_COST_THRESHOLD) {
188-
checkForEarlyTermination();
189-
}
190-
}
191-
192182
/**
193183
* Checks if the Driver associated with this DriverContext has been cancelled or early terminated.
194184
*/
195185
public void checkForEarlyTermination() {
196-
accumulatedCostForEarlyTermination = 0;
197186
earlyTerminationChecker.run();
198187
}
199188

@@ -202,17 +191,10 @@ public void checkForEarlyTermination() {
202191
* This method should be called when associating this DriverContext with a driver.
203192
*/
204193
public void initializeEarlyTerminationChecker(Runnable checker) {
205-
this.earlyTerminationChecker = checker;
206-
}
207-
208-
/**
209-
* Returns the estimated batch size for early termination based on the given estimate cost for each item.
210-
*/
211-
public static int estimateBatchSizeForEarlyTermination(int estimateCost) {
212-
if (estimateCost <= 0) {
213-
return CHECK_FOR_EARLY_TERMINATION_COST_THRESHOLD;
194+
if (this.earlyTerminationChecker != NO_OP) {
195+
throw new IllegalStateException("Early termination checker already initialized");
214196
}
215-
return Math.max(CHECK_FOR_EARLY_TERMINATION_COST_THRESHOLD / estimateCost, 1);
197+
this.earlyTerminationChecker = checker;
216198
}
217199

218200
/**

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/evaluator/predicate/operator/logical/NotEvaluator.java

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/GreatestBooleanEvaluator.java

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/GreatestBytesRefEvaluator.java

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/GreatestDoubleEvaluator.java

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/GreatestIntEvaluator.java

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/GreatestLongEvaluator.java

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/LeastBooleanEvaluator.java

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/src/main/generated/org/elasticsearch/xpack/esql/expression/function/scalar/conditional/LeastBytesRefEvaluator.java

Lines changed: 12 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)