aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches-Unmapped/0380-Performance-improvement-for-Chunk.getEntities.patch
diff options
context:
space:
mode:
Diffstat (limited to 'Spigot-Server-Patches-Unmapped/0380-Performance-improvement-for-Chunk.getEntities.patch')
-rw-r--r--Spigot-Server-Patches-Unmapped/0380-Performance-improvement-for-Chunk.getEntities.patch35
1 files changed, 35 insertions, 0 deletions
diff --git a/Spigot-Server-Patches-Unmapped/0380-Performance-improvement-for-Chunk.getEntities.patch b/Spigot-Server-Patches-Unmapped/0380-Performance-improvement-for-Chunk.getEntities.patch
new file mode 100644
index 0000000000..0b09feb060
--- /dev/null
+++ b/Spigot-Server-Patches-Unmapped/0380-Performance-improvement-for-Chunk.getEntities.patch
@@ -0,0 +1,35 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: wea_ondara <[email protected]>
+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 c36f55f178166eb099cc5c64784be5a9f4750199..8ade81a693286cdf65f8c0eeca2121a217c90350 100644
+--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
++++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+@@ -117,14 +117,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.world.entity.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.world.entity.Entity entity : chunk.entitySlices[i]) {
++ if (entity == null) {
+ continue;
+ }
+-
+- entities[index++] = ((net.minecraft.world.entity.Entity) obj).getBukkitEntity();
++ entities[index++] = entity.getBukkitEntity();
+ }
++ // Paper end
+ }
+
+ return entities;