From a2d9f33ca38660bb6bd698f598e8a6cfddc4e702 Mon Sep 17 00:00:00 2001 From: Travis Watkins Date: Thu, 11 Apr 2013 18:11:10 -0500 Subject: [PATCH] Various minor performance improvements Add a check to avoid doing movement work if an entity doesn't move. This usually will not ever happen in the current server but is useful when it does and will be more useful in the future. Only process mob on mob (non-player) collisions every other tick. Players tend to pack a lot of mobs into a small space (sheep farm, mob grinder, etc) so they do a lot of work processing collisions. To help alleviate some of this we only run these calculations every other tick. This has no visible effect on the client but can be a huge win on the server depending on circumstances. Use generic entity inWater checking for squids. Squids have their own logic currently for determining if they are in water. This check is almost identical to the generic entity checking which is run anyway. To avoid doing duplicate work we just remove the squid version. This does not have any noticeable effect on gameplay since the checks are so similar. Use HashSet for tile entities instead of ArrayList. Using an ArrayList for storing tile entities in a world means we have very expensive inserts and removes that aren't at the end of the array due to the array copy this causes. This is most noticeable during chunk unload when a large number of tile entities are removed from the world at once. Using a HashSet here uses a little more memory but is O(1) for all operations so removes this bottleneck. --- src/main/java/net/minecraft/server/Entity.java | 6 ++++++ src/main/java/net/minecraft/server/EntityLiving.java | 6 ++++++ src/main/java/net/minecraft/server/EntitySquid.java | 2 ++ src/main/java/net/minecraft/server/World.java | 3 +-- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java index 51a5b38cc3..d510392ec6 100644 --- a/src/main/java/net/minecraft/server/Entity.java +++ b/src/main/java/net/minecraft/server/Entity.java @@ -417,6 +417,12 @@ public abstract class Entity { } public void move(double d0, double d1, double d2) { + // CraftBukkit start - Don't do anything if we aren't moving + if (d0 == 0 && d1 == 0 && d2 == 0) { + return; + } + // CraftBukkit end + if (this.Z) { this.boundingBox.d(d0, d1, d2); this.locX = (this.boundingBox.a + this.boundingBox.d) / 2.0D; diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 21819eeb96..fd1327a421 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -1411,6 +1411,12 @@ public abstract class EntityLiving extends Entity { for (int i = 0; i < list.size(); ++i) { Entity entity = (Entity) list.get(i); + // CraftBukkit start - Only handle mob (non-player) collisions every other tick + if (entity instanceof EntityLiving && !(this instanceof EntityPlayer) && this.ticksLived % 2 == 0) { + continue; + } + // CraftBukkit end + if (entity.L()) { this.o(entity); } diff --git a/src/main/java/net/minecraft/server/EntitySquid.java b/src/main/java/net/minecraft/server/EntitySquid.java index be8a5ed793..c6e8f786d3 100644 --- a/src/main/java/net/minecraft/server/EntitySquid.java +++ b/src/main/java/net/minecraft/server/EntitySquid.java @@ -63,9 +63,11 @@ public class EntitySquid extends EntityWaterAnimal { // CraftBukkit end } + /* CraftBukkit start - Delegate to Entity to use existing inWater value public boolean G() { return this.world.a(this.boundingBox.grow(0.0D, -0.6000000238418579D, 0.0D), Material.WATER, (Entity) this); } + // CraftBukkit end */ public void c() { super.c(); diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index 03b716743b..d896f69209 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -30,7 +30,7 @@ public abstract class World implements IBlockAccess { public boolean d = false; public List entityList = new ArrayList(); protected List f = new ArrayList(); - public List tileEntityList = new ArrayList(); + public Set tileEntityList = new HashSet(); // CraftBukkit - ArrayList -> HashSet private List a = new ArrayList(); private List b = new ArrayList(); public List players = new ArrayList(); @@ -44,7 +44,6 @@ public abstract class World implements IBlockAccess { protected float o; protected float p; public int q = 0; - // public boolean suppressPhysics = false; // CraftBukkit (removed in vanilla) public boolean callingPlaceEvent = false; // CraftBukkit public int difficulty; public Random random = new Random();