Skip to content

Commit a24bf7b

Browse files
committed
DefaultEventBus: avoid publishing events nobody is interested in
The AWT EventQueue is really slow: EventQueue.invokeAndWait() can take up to 30x as long as creating a new thread and starting it on the provided Runnable. If there is not even a subscriber to the event we are about to send, let's just not bother. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 763457e commit a24bf7b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/main/java/org/scijava/event/DefaultEventBus.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ private void publishNow(final Object event, final String topic,
190190
@SuppressWarnings("rawtypes") final List vetoSubscribers,
191191
final StackTraceElement[] callingStack)
192192
{
193+
if (subscribers == null || subscribers.isEmpty()) return;
193194
try {
194195
threadService.invoke(new Runnable() {
195196

@@ -216,6 +217,7 @@ private void publishLater(final Object event, final String topic,
216217
@SuppressWarnings("rawtypes") final List vetoSubscribers,
217218
final StackTraceElement[] callingStack)
218219
{
220+
if (subscribers == null || subscribers.isEmpty()) return;
219221
threadService.run(new Runnable() {
220222

221223
@Override

0 commit comments

Comments
 (0)