Optimize event dispatch when no listeners are registered - #14173
Conversation
|
Allocation samples are probably not a very good metric. What other measurements did you use that show a clear benefit? |
|
Yeah, that's fair — allocation samples alone aren't really enough to show the actual impact. I only used them as supporting evidence that the unnecessary event allocations are being removed. I also ran a controlled synthetic test with:
The results were:
Main-thread CPU time over the measurement window:
That CPU time is for the main thread as a whole during the measurement window, not time spent exclusively inside the event-dispatch methods. The allocation and GC numbers are just supporting evidence here, not the main performance measurement. This is still a synthetic workload designed to isolate this specific event path, so these results shouldn't be generalized to production-scale performance. I can also provide the raw JFR files from the runs if that would be useful. |
|
Can you share the benchmark/workload setup? Only seeing the code that is run allows judging the results in any way. |
|
The full benchmark/workload setup is included in Paper-14153-benchmark.zip. It contains the test plugin and code used for the measurements. |
Fixes #14153
What does this PR do?
Optimizes Bukkit event handling in frequently executed paths by checking for registered listeners before creating and dispatching events.
Affected areas:
EntityInsideBlockEvent.When listeners exist, the guarded event paths remain unchanged:
No public API or listener registration behavior was changed.
When no listeners are registered, event dispatch is skipped while normal vanilla behavior remains.
Testing
Validated with:
:paper-server:compileJavafixupSourcePatchesrebuildPatchesbuildgit diff --cached --checkListener-enabled test:
Listener-disabled test:
Java Flight Recorder was used with a synthetic workload as allocation evidence:
This is targeted validation evidence only and is not a production benchmark or a percentage performance measurement.
The synthetic vehicle workload did not successfully trigger the vanilla vehicle event paths, so those paths were not runtime validated.
AI Assistance Disclosure
AI assistance was used for repository inspection and implementation assistance.
I reviewed the changes, understand the implementation, and verified the results before submission.