ohowe1 / SpectatorModeRewrite

Minecraft plugin that allows players to go into spectator mode but enables admins to prevent features of it.
https://www.spigotmc.org/resources/smp-spectator-mode-1-16-support.77267/
MIT License
17 stars 9 forks source link

Performance #44

Closed BumbleTree closed 3 years ago

BumbleTree commented 3 years ago

Is your feature request related to a problem? Please describe. Plugin is most thread intensive plugin even with 0 people in spec and few people online

Describe the solution you'd like It not to make player movement checks 24/7

This plugins usefulness is great however considering 0 people are in spec i believe it shouldn't be the most performance lossy plugin i have.

ohowe1 commented 3 years ago

The plugin only processes any event if that player is in spectator which should not have a large performance issue especially if no one is in spectator. I'll look into it but are there any other details?

DeJayDev commented 3 years ago

This plugin runs shouldCancelMoveEvent whenever PlayerMoveEvent is triggered. This event is fired even for changes that don't include directional movement such as yaw/pitch.

The dumbest fix would be to run these in two different blocks rather than compare the responses of both. You don't want to be doing all the logic checking for both then cancelling the event. It'll still have to process the results of both variables. Consider also just completely aborting and returning if only the yaw/pitch changes.

https://github.com/carelesshippo/SpectatorModeRewrite/blob/d50a29507073aedfcbacaf94ee83767e44cd94f1/src/main/java/me/ohowe12/spectatormode/listener/OnMoveListener.java#L54

if (!shouldProcessEvent(moveEvent)) {
    return;
}
if (shouldCancelMoveEvent(moveEvent)) {
    cancelPlayerMoveEvent(moveEvent);
}
ohowe1 commented 3 years ago

The plugin first runs the shouldProcess function then if that is true it runs the shouldCancel as it uses the && operator instead of the & operator so that should not be necessary.

BumbleTree commented 3 years ago

Well I can't comment on the code but the plugin was using up 1.8% of the server tick. With the next pkugin using 0.4%. And this had 0 players in spectator with only 15 online

ohowe1 commented 3 years ago

I'll look into it when I can.

ohowe1 commented 3 years ago

From what I found on my test with just me is that the 1.8% is just the onmovelisteners quick if that runs. I don't think that their is a way to fasten this up.