From 9ea1f9ee3da09df66a5ed3e978327615a987ab9a Mon Sep 17 00:00:00 2001 From: weaondara Date: Sun, 20 Oct 2019 00:33:35 +0200 Subject: [PATCH] performance improvement for CraftChunk.getEntities() (#2629) --- ...ce-improvement-for-Chunk.getEntities.patch | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Spigot-Server-Patches/0419-Performance-improvement-for-Chunk.getEntities.patch diff --git a/Spigot-Server-Patches/0419-Performance-improvement-for-Chunk.getEntities.patch b/Spigot-Server-Patches/0419-Performance-improvement-for-Chunk.getEntities.patch new file mode 100644 index 000000000..5c9f9ceba --- /dev/null +++ b/Spigot-Server-Patches/0419-Performance-improvement-for-Chunk.getEntities.patch @@ -0,0 +1,38 @@ +From 62af6667746cc668375eb2e6f02352fbcded8c7c Mon Sep 17 00:00:00 2001 +From: wea_ondara +Date: Thu, 10 Oct 2019 11:29:42 +0200 +Subject: [PATCH] Performance improvement for Chunk.getEntities + +This patch aims to reduce performance cost used by collecting the +entities of a chunk. Previously the entitySlices were copied into an +extra array with List.toArray() with is a costly and unneccessary +operation. This patch will reduce the load of plugins which for example +implement custom moblimits and depend on Chunk.getEntities(). + +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +index b4551614..373bea4b 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java +@@ -110,14 +110,14 @@ public class CraftChunk implements Chunk { + Entity[] entities = new Entity[count]; + + for (int i = 0; i < 16; i++) { +- +- for (Object obj : chunk.entitySlices[i].toArray()) { +- if (!(obj instanceof net.minecraft.server.Entity)) { ++ // Paper start - speed up (was with chunk.entitySlices[i].toArray() and cast checks which costs a lot of performance if called often) ++ for (net.minecraft.server.Entity entity : chunk.entitySlices[i]) { ++ if (entity == null) { + continue; + } +- +- entities[index++] = ((net.minecraft.server.Entity) obj).getBukkitEntity(); ++ entities[index++] = entity.getBukkitEntity(); + } ++ // Paper end + } + + return entities; +-- +2.23.0 +