-
-
Notifications
You must be signed in to change notification settings - Fork 307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce Citizens ticking #2110
Reduce Citizens ticking #2110
Conversation
It is generally considered good etiquette to discuss whether opening a PR is appropriate on Discord before submitting one at all. |
This is functionally unpullable until it either Until one of those is met, this has a very high risk of causing issues on any servers that update to a build containing this PR. This could probably benefit from being configurable on a per-NPC basis in addition to a I'd advise B (configurable and default off) as the way to go and be safe, but an attempt at A to account for more likely issues would be nice (but can be delayed for later commits or PRs if B is already in place, as it would be limitations of an option rather than fundamentally breaking existing things). Side note, but I'd encourage you to check over your git or editor settings to avoid recommitting entire files with changed line endings. Not super important but would be nice. |
I'd probably split this PR into the lookclose changes and the shouldTick changes. Currently the shouldTick changes are really broad. With the lookclose change, I'd probably a) use the Entity#getLocation(Location) method and b) use distanceSquared > some minimum delta instead of equals. Have you profiled just the lastKnownLocation change in isolation? Also, please fix the line endings. |
@Cryptite do you plan to revise this PR per the comments above? |
It may be some time until I can return to this. Busy updating my server to 1.15 among some other things. If there's a desire to close this in favor of a more focused PR (or two) in the future that is fine by me. |
This comment has been minimized.
This comment has been minimized.
# Conflicts: # main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
# Conflicts: # main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
# Conflicts: # main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java # main/src/main/java/net/citizensnpcs/trait/LookClose.java
Any news on this or is this dead? |
I'm going to close this as I don't plan to revisit this in the near future. I believe some of the changes to LookClose were implemented quite awhile ago in Citizens, and my ticking changes aren't stable or well thought-out enough to handle other cases. If this were revisited, it should likely be a fresh PR. |
Thanks for the PR anyway, it definitely raises some points. |
This is only the first pass at a change to ticking Citizens and is likely incomplete so this PR seeks review and feedback.
What this PR aims to solve for is the quantity of ticking done to unmoving Citizens. Your average NPC is likely static and unmoving. Even if they have the LookClose trait, they still spend the vast majority of their time not looking at anybody or if they are, often that player might not be moving.
This PR reduces ticks by up to 1/20th the time as updates about static NPCs are largely unnecessary and the "Update at least once a second" paradigm is pretty common throughout tick-reduction PRs throughout Minecraft.
In effect, this PR will tick
EntityHumanNPC
under the following conditions:It is possible ticking could be reduce further, perhaps behind a config option as even 1s is probably too often to update NPCs who might never move, pathfind, have potion effects, change armor, etc.
One thing this doesn't account for and probably should is the Gravity trait.
On Loka with 30 players this has reduced the overall performance hit of the
PlayerUpdateTask
from 5% of the server tick to around or less than 1%.As an unrelated addition this PR also fixes a problem where
hasInvalidTarget
was not checking the squaredrange
and so was invalidating its target each tick.