Speed up MockSinglePrioritizingExecutor (#61011) (#61012)

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.
This commit is contained in:
Armin Braun 2020-08-12 12:24:04 +02:00 committed by GitHub
parent 66098e0bf4
commit 3a046e125d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -58,8 +58,9 @@ public class MockSinglePrioritizingExecutor extends PrioritizedEsThreadPoolExecu
@Override @Override
protected void afterExecute(Runnable r, Throwable t) { protected void afterExecute(Runnable r, Throwable t) {
super.afterExecute(r, t); super.afterExecute(r, t);
// kill worker so that next one will be scheduled // kill worker so that next one will be scheduled, using cached Error instance to not incur the cost of filling in the stack trace
throw new KillWorkerError(); // on every task
throw KillWorkerError.INSTANCE;
} }
@Override @Override
@ -69,5 +70,6 @@ public class MockSinglePrioritizingExecutor extends PrioritizedEsThreadPoolExecu
} }
private static final class KillWorkerError extends Error { private static final class KillWorkerError extends Error {
private static final KillWorkerError INSTANCE = new KillWorkerError();
} }
} }