Feature: Optimize handleMove#142
Conversation
|
Excellent, I too was about to start looking into it as well, as it was often the laggiest method running for me too. |
| // Add the chunk to the cache | ||
| loadedChunks | ||
| .computeIfAbsent(world, w -> new HashSet<>()) | ||
| .add(chunkKey(chunk.getX(), chunk.getZ())); |
There was a problem hiding this comment.
I would advise just using Chunk.getChunkKey() and storing the long this provides instead of a String. It is much more efficient than constructing a string on every single chunk load, unload, and player movement.
There was a problem hiding this comment.
I don't think getChunkKey is an api that is available since 1.8, let alone in spigot/bukkit.
There was a problem hiding this comment.
It's available in the paper-api since I think about 1.12, but all the same, here's the method:
static long getChunkKey(int x, int z) {
return (long)x & 4294967295L | ((long)z & 4294967295L) << 32;
}
| for (Npc<World, Player, ItemStack, Plugin> npc : this.npcTracker.trackedNpcs()) { | ||
| // check if the player is still in the same world as the npc | ||
| Position pos = npc.position(); | ||
| if (!npc.world().equals(player.getWorld()) || !npc.world().isChunkLoaded(pos.chunkX(), pos.chunkZ())) { |
There was a problem hiding this comment.
In all honestly, I think a better call here would be for NPCs to store state as to whether they are in a loaded chunk or not, rather than rely on every single small player movement to check if they are in a loaded chunk.
|
Any updates on this one? |
|
@adabugra are you still working on this? else I (or someone else) could maybe take this over |
I will look into this when I have time. What changes are needed? |
This PR optimizes the handleMove method in the BukkitActionController class by introducing chunk caching and movement tick skipping. These enhancements reduce unnecessary calculations and improves performance.
Tests (~550 online/real players):
Before:

After:
