Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hasListeners()/hasAnyListeners() to avoid unnecessary event object instantiation #51

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

PaintNinja
Copy link
Contributor

@PaintNinja PaintNinja commented Jul 24, 2023

Adds these static methods:

  • Event.hasListeners(bus)
  • Event.hasAnyListeners()
  • Event.getListenerListStatically()

Transformer changes getListenerListStatically() to grab the same static field that the instance method does.

The hasListeners()/hasAnyListeners() methods check the ListenerList's array size directly - no hashsets or additional memory overhead.

JMH benchmark results:

Benchmark                                                             Mode  Cnt    Score   Error  Units
EventBusBenchmark.testClassLoaderCombined                             avgt   15   42.212 � 0.436  ns/op
EventBusBenchmark.testClassLoaderCombinedHasAnyListeners              avgt   15   34.442 � 0.791  ns/op
EventBusBenchmark.testClassLoaderCombinedHasListeners                 avgt   15    5.480 � 0.042  ns/op
EventBusBenchmark.testModLauncherCombined                             avgt   15   41.072 � 0.339  ns/op
EventBusBenchmark.testModLauncherCombinedHasAnyListeners              avgt   15   34.047 � 0.224  ns/op
EventBusBenchmark.testModLauncherCombinedHasListeners                 avgt   15    5.510 � 0.042  ns/op
EventBusBenchmarkNoLoader.testNoLoaderCombined                        avgt   15  170.711 � 3.025  ns/op
EventBusBenchmarkNoLoader.testNoLoaderCombinedHasAnyListeners         avgt   15   12.390 � 0.046  ns/op
EventBusBenchmarkNoLoader.testNoLoaderCombinedHasListeners            avgt   15    5.319 � 0.067  ns/op

jmh-log.txt
jmh_results.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant