From a154f9c657d18d841359859cb2850eb66bc1f333 Mon Sep 17 00:00:00 2001 From: Jason Tedor Date: Mon, 2 Mar 2020 23:27:33 -0500 Subject: [PATCH] Early return if no global checkpoint listeners (#53036) When notifying global checkpoint listeners, we have an opportunity to early return if there are not any registered listeners. This is important since it saves some allocations, and also saves forking some empty work to another thread. This commit adds an early return from notifying listeners if there are not any registered. --- .../elasticsearch/index/shard/GlobalCheckpointListeners.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/shard/GlobalCheckpointListeners.java b/server/src/main/java/org/elasticsearch/index/shard/GlobalCheckpointListeners.java index d45a77ddb22..57e28d96ad2 100644 --- a/server/src/main/java/org/elasticsearch/index/shard/GlobalCheckpointListeners.java +++ b/server/src/main/java/org/elasticsearch/index/shard/GlobalCheckpointListeners.java @@ -195,6 +195,11 @@ public class GlobalCheckpointListeners implements Closeable { assert Thread.holdsLock(this) : Thread.currentThread(); assertNotification(globalCheckpoint, e); + // early return if there are no listeners + if (listeners.isEmpty()) { + return; + } + final Map>> listenersToNotify; if (globalCheckpoint != UNASSIGNED_SEQ_NO) { listenersToNotify =