Paper/Spigot-Server-Patches/0380-Performance-improvement-for-Chunk.getEntities.patch
Daniel Ennis e792da723a
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#4728)
Upstream has released updates that appears to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
30885166 Update to Minecraft 1.16.4

CraftBukkit Changes:
3af81c71 Update to Minecraft 1.16.4

Spigot Changes:
f011ca24 Update to Minecraft 1.16.4

Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com>
2020-11-02 20:22:15 -06:00

36 lines
1.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: wea_ondara <wea_ondara@alpenblock.net>
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 d40ef8353b2c025309144b4123d6a7dff04a9c62..26210b233bb40565326cf25f568dca0984ce7313 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
@@ -115,14 +115,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;