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.
This commit is contained in:
Jason Tedor 2020-03-02 23:27:33 -05:00
parent 5cffa14f45
commit a154f9c657
No known key found for this signature in database
GPG Key ID: FA89F05560F16BC5
1 changed files with 5 additions and 0 deletions

View File

@ -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<GlobalCheckpointListener, Tuple<Long, ScheduledFuture<?>>> listenersToNotify;
if (globalCheckpoint != UNASSIGNED_SEQ_NO) {
listenersToNotify =