Skip Folia's EntityScheduler executeTick checks if the scheduler hasn't been used at least once#9984
Closed
MrPowerGamerBR wants to merge 2 commits into
Closed
Conversation
…'t been used at least once
kennytv
requested changes
Nov 29, 2023
Contributor
Author
|
I have made another PR that also solves the same issue, but that one is based off the patch I mentioned in this PR's description: #9985 I decided to open a new PR instead of editing this one because I think both approaches are nice:
|
Member
|
Closing this in favor of #9985 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
hasScheduledAtLeastOneTaskoutside of a synchronized block) and probably has a better solution.Folia's EntityScheduler
executeTickloop inMinecraftServer'stickChildrenis 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
executeTickdoes. 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