Repository navigation
perf: group events by type once per load - #6
Merged
Merged
Conversation
getValidEvents scanned every loaded event on each Bukkit event and on each outgoing chat packet (the ProtocolLib listener, ~0.3 s/h on Main with no event of that type). Events are now indexed by type in setEvents; enabled is still checked per call because /ce enable and /ce disable change it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
@coderabbitai review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
EventsManager.getValidEvents(type)walked every loaded event (about 150 on Main) on every Bukkit event CE listens to: each interact, command, move-type event and so on. The ProtocolLib listener also calls it for every outgoing chat packet. In Main's 11-02/11-03 spark profiles that listener alone cost about 0.3 s/h on the main thread, although Main has noprotocollib_receive_messageevent.What changes
setEventsbuilds anEnumMap<EventType, List<CEEvent>>once per load or reload. It is held in a volatile field, because the ProtocolLib listener reads it off the main thread.getValidEventsandgetEventsByTyperead only that type's list, in the same file order as before.isEnabledis still checked on every call, because/ce enableand/ce disablechange it at runtime without a reload.ArrayList, so nothing that edits the returned list can change the index.There is no behaviour change. The only place that sets the event type is the loader, before
setEvents.Tests
EventsManagerIndexTestcovers type and order, disabled events, a type with no events, enabling at runtime, reload, and that callers get copies.mvn verify: 44 tests pass, and the character-package coverage check passes.🤖 Generated with Claude Code