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.
Dieser Commit ist enthalten in:
Travis Watkins 2013-04-11 18:11:10 -05:00 committet von Wesley Wolfe
Ursprung 159d614a3a
Commit a2d9f33ca3
4 geänderte Dateien mit 15 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -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();