Skip to content

perf: group events by type once per load - #6

Merged
XxFran10xX merged 1 commit into
mainfrom
perf/events-by-type
Nov 3, 2026
Merged

XxFran10xX merged 1 commit into
mainfrom
perf/events-by-type

Conversation

@XxFran10xX

Copy link
Copy Markdown
Contributor

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 no protocollib_receive_message event.

What changes

  • setEvents builds an EnumMap<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.
  • getValidEvents and getEventsByType read only that type's list, in the same file order as before.
  • isEnabled is still checked on every call, because /ce enable and /ce disable change it at runtime without a reload.
  • Callers still get their own 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

EventsManagerIndexTest covers 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

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>
@XxFran10xX

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Nov 3, 2026
@XxFran10xX
XxFran10xX merged commit bf2bf9f into main Nov 3, 2026
2 checks passed
@XxFran10xX
XxFran10xX deleted the perf/events-by-type branch November 3, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant