Skip to content

Fix #10323: Inefficient Ender Dragon Respawn #12349

Closed
AfonsoMendoncaJacinto wants to merge 1 commit into
PaperMC:mainfrom
AfonsoMendoncaJacinto:PIC
Closed

Fix #10323: Inefficient Ender Dragon Respawn #12349
AfonsoMendoncaJacinto wants to merge 1 commit into
PaperMC:mainfrom
AfonsoMendoncaJacinto:PIC

Conversation

@AfonsoMendoncaJacinto
Copy link
Copy Markdown

@AfonsoMendoncaJacinto AfonsoMendoncaJacinto commented Mar 27, 2025

This fixes issue #10323. Currently, the respawn sequence of the Ender Dragon has a noticeable lag spike, likely caused by the method findExitPortal() being poorly optimized, and calling the method find() (which is an expensive method, in terms of server execution time) multiple times, unnecessarily.

Solution: fix index incrementation and direct the search to the most likely spot first, instead of iterating over various blocks, calling find() without first checking whether it makes sense to call it for the instance of the block considered. Also, pre-fetching the relevant chunk does improve following computations.

Profiler links
under stress original version: https://spark.lucko.me/4gqvxg7QBt?hl=9025
under stress with modification: https://spark.lucko.me/tyLvsstn9J?hl=4886

As you can see, the method findExitPortal() is nowhere to be seen, in the second profile report, indicating little impact on server performance. Also, the execution time of the method scanState() went from 5360ms to 60ms.

This issue likely arose from the method findExitPortal(),
which has been optimized. This optimization will ensure
better server performance during the respawn sequence
and smoother gameplay.

Signed-off-by: Afonso Jacinto
<afonso.mendonca.jacinto@tecnico.ulisboa.pt>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed

Development

Successfully merging this pull request may close these issues.

1 participant