Skip to content

Commit

Permalink
Early return if no global checkpoint listeners (#53036)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jasontedor committed Mar 3, 2020
1 parent 4144791 commit b7f8fa0
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ private void notifyListeners(final long globalCheckpoint, final IndexShardClosed
assert Thread.holdsLock(this) : Thread.currentThread();
assertNotification(globalCheckpoint, e);

// early return if there are no listeners
if (listeners.isEmpty()) {
return;
}

final Map<GlobalCheckpointListener, Tuple<Long, ScheduledFuture<?>>> listenersToNotify;
if (globalCheckpoint != UNASSIGNED_SEQ_NO) {
listenersToNotify =
Expand Down

0 comments on commit b7f8fa0

Please sign in to comment.