Skip to content

Commit 9264a0f

Browse files
Speed up MockSinglePrioritizingExecutor (#61011)
Found this while checking if I can speed up SnapshotResiliencyTests to get more coverage/time. Turns out throwing a new instance here on every task was taking 9% of the CPU wall-time in those tests. With this change it's 4% of the overall.
1 parent 679da50 commit 9264a0f

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test/framework/src/main/java/org/elasticsearch/cluster/coordination/MockSinglePrioritizingExecutor.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,9 @@ public String toString() {
5858
@Override
5959
protected void afterExecute(Runnable r, Throwable t) {
6060
super.afterExecute(r, t);
61-
// kill worker so that next one will be scheduled
62-
throw new KillWorkerError();
61+
// kill worker so that next one will be scheduled, using cached Error instance to not incur the cost of filling in the stack trace
62+
// on every task
63+
throw KillWorkerError.INSTANCE;
6364
}
6465

6566
@Override
@@ -69,5 +70,6 @@ public boolean awaitTermination(long timeout, TimeUnit unit) {
6970
}
7071

7172
private static final class KillWorkerError extends Error {
73+
private static final KillWorkerError INSTANCE = new KillWorkerError();
7274
}
7375
}

0 commit comments

Comments
 (0)