2020-02-11 05:35:46 +01:00
|
|
|
From 9961ec0865c5a0e65986c223b7dfaf11aaa91f3c Mon Sep 17 00:00:00 2001
|
2019-10-20 00:33:35 +02:00
|
|
|
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
|
2020-01-22 03:02:07 +01:00
|
|
|
index 91f2066b1..9cff8b88b 100644
|
2019-10-20 00:33:35 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftChunk.java
|
2019-12-13 15:08:40 +01:00
|
|
|
@@ -112,14 +112,14 @@ public class CraftChunk implements Chunk {
|
2019-10-20 00:33:35 +02:00
|
|
|
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;
|
|
|
|
--
|
2020-01-30 10:36:03 +01:00
|
|
|
2.25.0
|
2019-10-20 00:33:35 +02:00
|
|
|
|