sekwah41 / Advanced-Portals

An advanced portals plugin for bukkit
GNU Lesser General Public License v3.0
157 stars 65 forks source link

Lag Caused by `PortalPlacer.onChunkLoad() #439

Open DarkChromaMC opened 2 months ago

DarkChromaMC commented 2 months ago

The AdvancedPortals plugin is causing significant server lag due to the com.sekwah.advancedportals.bukkit.listeners.PortalPlacer.onChunkLoad() method being called every time a chunk loads. This issue is particularly noticeable when new chunks are being generated. In our server setup, the portal block is only used once for creating portals at Spawn and is never used again, making the frequent calls to this method unnecessary and performance-heavy.

Steps to Reproduce:

  1. Install the AdvancedPortals plugin on a Minecraft server.
  2. Ensure the server has areas where new chunks are frequently generated (e.g., exploring new areas).
  3. Monitor server performance and observe the high CPU usage and lag spikes correlated with chunk loads.

Expected Behavior: The PortalPlacer.onChunkLoad() method should not cause significant lag, especially when the portal block is infrequently used.

Observed Behavior: Low TPS is observed when chunks are loaded, due to the PortalPlacer.onChunkLoad() method being called excessively.

Impact: This issue severely impacts server performance, making it difficult to provide a smooth gameplay experience, especially in areas with high rates of chunk generation like players flying with an elytra.

Environment:

Proposed Solutions:

  1. Introduce a setting in the plugin's configuration file to disable the onChunkLoad listener for servers that do not need it.
  2. Optimize the onChunkLoad method to reduce its performance impact. This could include caching results or reducing the frequency of operations performed during chunk load events.
  3. Implement a conditional check to ensure the onChunkLoad method only processes chunks if they contain relevant portal blocks, avoiding unnecessary processing for chunks without portals.

Additional Context: Our server primarily uses portal blocks at Spawn for initial setup, and they are rarely used elsewhere. Therefore, the frequent calls to onChunkLoad are unnecessary in our context and degrade server performance.

Attachments: https://spark.lucko.me/6rbL5fAZds?hl=752

Thank you for your attention to this issue. Optimizing or providing a way to disable this feature would greatly enhance server performance and player experience.

sekwah41 commented 2 months ago

I have plans to optimise it as paper has a value you can pass to it but spigots implementation is super inefficient. Though adding a value to toggle it would be good.