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

Fix EventBus Performance issues #193

Merged
merged 1 commit into from
Jun 28, 2023
Merged

Fix EventBus Performance issues #193

merged 1 commit into from
Jun 28, 2023

Conversation

JamesTKhan
Copy link
Owner

@JamesTKhan JamesTKhan commented Jun 27, 2023

While working on a feature branch, I noticed a frame drop when posting evens often. I looked into the EventBus code for the first time and saw some areas for improvement. Every time an event was posted the EventBus searched through every subscriber, check that it is a subscriber, and then find and call the event method all of this using reflection was quite slow.

Updated the EventBus class to perform the reflection logic on Register instead, and then cache Event class -> Subscriber in a map for fast lookup on Post so now we only perform the slow operations once on register. Also cleaned up the class a bit and added more code documentation to the methods.

Additionally, added a junit test for the EventBus.

In a quick performance test of posting 100 events with 100 subscribers, the old code took 22ms, the new code took 2ms.

@JamesTKhan JamesTKhan requested a review from Dgzt June 27, 2023 19:51
@JamesTKhan JamesTKhan changed the title EventBus Performance issues Fix EventBus Performance issues Jun 27, 2023
@JamesTKhan JamesTKhan merged commit d6a6e27 into master Jun 28, 2023
@JamesTKhan JamesTKhan deleted the eventbus-performance branch June 28, 2023 19:32
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.

2 participants