3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00

Fix some performance regression in last patch

Dieser Commit ist enthalten in:
Aikar 2018-08-18 12:42:17 -04:00
Ursprung e5d57793d2
Commit ecf97ddca0
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 401ADFC9891FAAFE

Datei anzeigen

@ -1,4 +1,4 @@
From 3facd0493823185b7d706fdea5f69d1aa4a0471b Mon Sep 17 00:00:00 2001
From 6b1a04d156cb28c9c7c99de5dcb2c420936ebd0d Mon Sep 17 00:00:00 2001
From: Colin Godsey <crgodsey@gmail.com>
Date: Wed, 8 Aug 2018 10:10:06 -0600
Subject: [PATCH] Cache World Entity Type counts
@ -7,10 +7,10 @@ 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 +1,114 @@
@@ -0,0 +1,121 @@
+package com.destroystokyo.paper;
+
+import net.minecraft.server.Entity;
@ -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,19 +132,23 @@ 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
@@ -123,6 +123,7 @@ 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
@@ -42,6 +42,7 @@ 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<PathType, Float> bH;
public MinecraftKey bI; // CraftBukkit private -> public
public long bJ; // CraftBukkit private -> public
@@ -614,6 +615,7 @@ public abstract class EntityInsentient extends EntityLiving {
@@ -614,6 +614,7 @@ public abstract class EntityInsentient extends EntityLiving {
return true;
}