From 7d5a5ed52f43c8aeadbad62c00384726d9db64ca Mon Sep 17 00:00:00 2001 From: Aikar Date: Sat, 18 Aug 2018 12:42:17 -0400 Subject: [PATCH] Fix some performance regression in last patch --- .../Cache-World-Entity-Type-counts.patch | 47 ++++++++++++------- 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Spigot-Server-Patches/Cache-World-Entity-Type-counts.patch b/Spigot-Server-Patches/Cache-World-Entity-Type-counts.patch index e529700df2..58f01f703c 100644 --- a/Spigot-Server-Patches/Cache-World-Entity-Type-counts.patch +++ b/Spigot-Server-Patches/Cache-World-Entity-Type-counts.patch @@ -7,7 +7,7 @@ Optimizes mob spawning by keeping a count of entities by type diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldEntityList.java b/src/main/java/com/destroystokyo/paper/PaperWorldEntityList.java new file mode 100644 -index 0000000000..f7b65ccf73 +index 0000000000..35104542c5 --- /dev/null +++ b/src/main/java/com/destroystokyo/paper/PaperWorldEntityList.java @@ -0,0 +0,0 @@ @@ -45,15 +45,13 @@ index 0000000000..f7b65ccf73 + + @Override + public boolean removeAll(Collection c) { -+ // TODO: Optimize this -+ boolean removed = false; + for (Object e : c) { -+ if (remove(e)) { -+ removed = true; ++ if (e instanceof Entity && ((Entity) e).getWorld() == world) { ++ updateEntityCount((Entity) e, -1); + } + } + -+ return removed; ++ return super.removeAll(c); + } + + @Override @@ -110,12 +108,21 @@ index 0000000000..f7b65ccf73 + if (entity instanceof EntityInsentient) { + EntityInsentient entityinsentient = (EntityInsentient) entity; + if (amt > 0 && entityinsentient.isDespawnableByDefault() && entityinsentient.isPersistent()) { -+ entityinsentient.countsAgainstSpawnLimit = false; -+ return; -+ } else if (amt < 0 && !entityinsentient.countsAgainstSpawnLimit) { + return; + } + } ++ if (amt < 0) { ++ if (!entity.hasBeenCounted) { ++ return; ++ } ++ // Only remove once, we remove from if the entity list is guarded, but may be called later ++ entity.hasBeenCounted = false; ++ } else { ++ if (entity.hasBeenCounted) { ++ return; ++ } ++ entity.hasBeenCounted = true; ++ } + + for (EnumCreatureType type : EnumCreatureType.values()) { + if (type.matches(entity)) { @@ -125,18 +132,22 @@ index 0000000000..f7b65ccf73 + } + } +} +diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java +index 41a951d580..03d54a7ef4 100644 +--- a/src/main/java/net/minecraft/server/Entity.java ++++ b/src/main/java/net/minecraft/server/Entity.java +@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke + private boolean az; + public boolean dead; + public boolean shouldBeRemoved; // Paper ++ public boolean hasBeenCounted = false; // Paper + public float width; + public float length; + public float J; diff --git a/src/main/java/net/minecraft/server/EntityInsentient.java b/src/main/java/net/minecraft/server/EntityInsentient.java -index 903434e5f4..0ad5e1ab47 100644 +index 903434e5f4..68765d2aad 100644 --- a/src/main/java/net/minecraft/server/EntityInsentient.java +++ b/src/main/java/net/minecraft/server/EntityInsentient.java -@@ -0,0 +0,0 @@ public abstract class EntityInsentient extends EntityLiving { - public float[] dropChanceArmor; - // public boolean canPickUpLoot; // CraftBukkit - moved up to EntityLiving - public boolean persistent; -+ public boolean countsAgainstSpawnLimit = true; // Paper - private final Map bH; - public MinecraftKey bI; // CraftBukkit private -> public - public long bJ; // CraftBukkit private -> public @@ -0,0 +0,0 @@ public abstract class EntityInsentient extends EntityLiving { return true; }