Skip Folia's EntityScheduler executeTick checks if the scheduler hasn't been used at least once #9984
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is mostly for "hey maybe there is a better solution for this", since I don't expect this PR to be accepted since it is mostly a hacky hack that probably has concurrency issues (accessing
hasScheduledAtLeastOneTask
outside of a synchronized block) and probably has a better solution.Folia's EntityScheduler
executeTick
loop inMinecraftServer
'stickChildren
is slooooow if you have a lot of entities (example: for a server with 15k entities, it uses ~1.7ms every tick, even if none of your plugins are using Folia's EntityScheduler)To workaround this, we just don't attempt to do any of the checks if the scheduler hasn't been used at least once. Yes, I know, the scheduler increments the
tickCount
, but that doesn't matter since all the scheduled tasks are "relative" to the current tick count, not bound to the server's tick count.The big performance boost comes from not needing to do all the checks
executeTick
does. Most server entities won't ever use a entity scheduler anyway, just think about it: Are plugins really going to add a scheduler to each item frame, each armor stand, each dropped item, each... you get my point.Another way of doing this is changing the scheduler to store entities that have pending tasks into a global list to avoid getting all entities from all worlds, this is what I have done in my fork, and maybe this is a better less hacky solution, BUT that will probably make Folia explode, this needs to be tested further in a Folia environment instead of a Paper environment (on a Paper environment, I have been using this patch for one week+ without any issues): https://github.com/SparklyPower/SparklyPaper/blob/ver/1.20.2/patches/server/0010-Skip-EntityScheduler-s-executeTick-checks-if-there-i.patch (See PR #9985)
If anyone wants to reproduce the performance impact: Just spawn a bunch of entities, I used Armor Stands to test this.
(In the profiler, the loop is
net.minecraft.server.MinecraftServer.lambda$tickChildren$15()
)Profiler Before the Changes: https://spark.lucko.me/eRvT1QqnI0
Profiler After the Changes: https://spark.lucko.me/DDAk1JQC0u