3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 05:20:07 +01:00

Performance update to remove several very high counts of temp object creation

Dieser Commit ist enthalten in:
Tahg 2011-12-06 08:52:45 -05:00
Ursprung eead44a692
Commit bc8f02788f
11 geänderte Dateien mit 223 neuen und 141 gelöschten Zeilen

Datei anzeigen

@ -175,7 +175,9 @@ public abstract class EntityLiving extends Entity {
this.extinguish(); this.extinguish();
} else { } else {
this.setAirTicks(maxAirTicks); // CraftBukkit - update maxAirTicks if no longer 300 if (this.getAirTicks() != 300) {
this.setAirTicks(maxAirTicks);
}
} }
this.aw = this.ax; this.aw = this.ax;

Datei anzeigen

@ -11,9 +11,9 @@ public class EntityTracker {
private IntHashMap trackedEntities = new IntHashMap(); private IntHashMap trackedEntities = new IntHashMap();
private MinecraftServer c; private MinecraftServer c;
private int d; private int d;
private int e; private World e; // CraftBukkit - change type
public EntityTracker(MinecraftServer minecraftserver, int i) { public EntityTracker(MinecraftServer minecraftserver, World i) { // CraftBukkit - change method signature
this.c = minecraftserver; this.c = minecraftserver;
this.e = i; this.e = i;
this.d = minecraftserver.serverConfigurationManager.a(); this.d = minecraftserver.serverConfigurationManager.a();
@ -94,7 +94,7 @@ public class EntityTracker {
this.a.add(entitytrackerentry); this.a.add(entitytrackerentry);
this.trackedEntities.a(entity.id, entitytrackerentry); this.trackedEntities.a(entity.id, entitytrackerentry);
entitytrackerentry.scanPlayers(this.c.getWorldServer(this.e).players); entitytrackerentry.scanPlayers(this.e.players); // CraftBukkit
} }
} }
@ -127,7 +127,7 @@ public class EntityTracker {
while (iterator.hasNext()) { while (iterator.hasNext()) {
EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next(); EntityTrackerEntry entitytrackerentry = (EntityTrackerEntry) iterator.next();
entitytrackerentry.track(this.c.getWorldServer(this.e).players); entitytrackerentry.track(this.e.players); // CraftBukkit
if (entitytrackerentry.m && entitytrackerentry.tracker instanceof EntityPlayer) { if (entitytrackerentry.m && entitytrackerentry.tracker instanceof EntityPlayer) {
arraylist.add((EntityPlayer) entitytrackerentry.tracker); arraylist.add((EntityPlayer) entitytrackerentry.tracker);
} }

Datei anzeigen

@ -267,7 +267,7 @@ public class MinecraftServer implements Runnable, ICommandListener, IMinecraftSe
this.server.getPluginManager().callEvent(new WorldInitEvent(world.getWorld())); this.server.getPluginManager().callEvent(new WorldInitEvent(world.getWorld()));
world.tracker = new EntityTracker(this, dimension); world.tracker = new EntityTracker(this, world); // CraftBukkit
world.addIWorldAccess(new WorldManager(this, world)); world.addIWorldAccess(new WorldManager(this, world));
world.difficulty = this.propertyManager.getInt("difficulty", 1); world.difficulty = this.propertyManager.getInt("difficulty", 1);
world.setSpawnFlags(this.propertyManager.getBoolean("spawn-monsters", true), this.spawnAnimals); world.setSpawnFlags(this.propertyManager.getBoolean("spawn-monsters", true), this.spawnAnimals);

Datei anzeigen

@ -1,5 +1,6 @@
package net.minecraft.server; package net.minecraft.server;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -7,11 +8,28 @@ import java.util.List;
import java.util.Random; import java.util.Random;
// CraftBukkit // CraftBukkit
import org.bukkit.craftbukkit.util.LongAbstractHashtable;
import org.bukkit.craftbukkit.util.EntryBase;
import org.bukkit.craftbukkit.util.LongHash;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
public final class SpawnerCreature { public final class SpawnerCreature {
private static HashMap b = new HashMap(); // private static HashMap b = new HashMap(); // CraftBukkit -- moved local to spawnEntities
static private class ChunkEntry extends EntryBase {
public boolean spawn;
public ChunkEntry (int x, int z, boolean spawn) {
super(LongHash.toLong(x, z));
this.spawn = spawn;
}
int getX() {
return LongHash.msw(key);
}
int getZ() {
return LongHash.lsw(key);
}
}
protected static final Class[] a = new Class[] { EntitySpider.class, EntityZombie.class, EntitySkeleton.class}; protected static final Class[] a = new Class[] { EntitySpider.class, EntityZombie.class, EntitySkeleton.class};
public SpawnerCreature() {} public SpawnerCreature() {}
@ -28,7 +46,9 @@ public final class SpawnerCreature {
if (!flag && !flag1) { if (!flag && !flag1) {
return 0; return 0;
} else { } else {
b.clear(); // b.clear(); // CraftBukkit
LongAbstractHashtable chunkCoords; // CraftBukkit
chunkCoords = new LongAbstractHashtable() {};
int i; int i;
int j; int j;
@ -43,19 +63,22 @@ public final class SpawnerCreature {
for (int l = -b0; l <= b0; ++l) { for (int l = -b0; l <= b0; ++l) {
for (int i1 = -b0; i1 <= b0; ++i1) { for (int i1 = -b0; i1 <= b0; ++i1) {
boolean flag2 = l == -b0 || l == b0 || i1 == -b0 || i1 == b0; boolean flag2 = l == -b0 || l == b0 || i1 == -b0 || i1 == b0;
ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(l + k, i1 + j); // CraftBukkit start
long chunkCoord = LongHash.toLong(l + k, i1 + j);
if (!flag2) { if (!flag2) {
b.put(chunkcoordintpair, Boolean.valueOf(false)); chunkCoords.put(new ChunkEntry(l + k, i1 + j, false));
} else if (!b.containsKey(chunkcoordintpair)) { } else if (!chunkCoords.containsKey(chunkCoord)) {
b.put(chunkcoordintpair, Boolean.valueOf(true)); chunkCoords.put(new ChunkEntry(l + k, i1 + j, true));
} }
// CraftBukkit end
} }
} }
} }
i = 0; i = 0;
ChunkCoordinates chunkcoordinates = world.getSpawn(); ChunkCoordinates chunkcoordinates = world.getSpawn();
ArrayList<EntryBase> entries = chunkCoords.entries(); // CraftBukkit
EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values(); EnumCreatureType[] aenumcreaturetype = EnumCreatureType.values();
j = aenumcreaturetype.length; j = aenumcreaturetype.length;
@ -63,15 +86,14 @@ public final class SpawnerCreature {
for (int j1 = 0; j1 < j; ++j1) { for (int j1 = 0; j1 < j; ++j1) {
EnumCreatureType enumcreaturetype = aenumcreaturetype[j1]; EnumCreatureType enumcreaturetype = aenumcreaturetype[j1];
if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= enumcreaturetype.b() * b.size() / 256) {
Iterator iterator = b.keySet().iterator(); if ((!enumcreaturetype.d() || flag1) && (enumcreaturetype.d() || flag) && world.a(enumcreaturetype.a()) <= enumcreaturetype.b() * entries.size() / 256) {
label108: label108:
while (iterator.hasNext()) { for (EntryBase base : entries) {
ChunkCoordIntPair chunkcoordintpair1 = (ChunkCoordIntPair) iterator.next(); ChunkEntry entry = (SpawnerCreature.ChunkEntry) base;
if (!entry.spawn) {
if (!((Boolean) b.get(chunkcoordintpair1)).booleanValue()) { ChunkPosition chunkposition = a(world, LongHash.msw(entry.getX()) * 16, entry.getZ() * 16);
ChunkPosition chunkposition = a(world, chunkcoordintpair1.x * 16, chunkcoordintpair1.z * 16);
int k1 = chunkposition.x; int k1 = chunkposition.x;
int l1 = chunkposition.y; int l1 = chunkposition.y;
int i2 = chunkposition.z; int i2 = chunkposition.z;

Datei anzeigen

@ -14,6 +14,8 @@ import java.util.UUID;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.craftbukkit.util.LongHash;
import org.bukkit.craftbukkit.util.LongHashset;
import org.bukkit.generator.ChunkGenerator; import org.bukkit.generator.ChunkGenerator;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
@ -74,7 +76,7 @@ public class World implements IBlockAccess {
private boolean S; private boolean S;
public boolean allowMonsters; // CraftBukkit - private -> public public boolean allowMonsters; // CraftBukkit - private -> public
public boolean allowAnimals; // CraftBukkit - private -> public public boolean allowAnimals; // CraftBukkit - private -> public
private Set T; private LongHashset T; // CraftBukkit
private int U; private int U;
int[] H; int[] H;
private List V; private List V;
@ -145,7 +147,7 @@ public class World implements IBlockAccess {
this.R = new ArrayList(); this.R = new ArrayList();
this.allowMonsters = true; this.allowMonsters = true;
this.allowAnimals = true; this.allowAnimals = true;
this.T = new HashSet(); this.T = new LongHashset(); // CraftBukkit
this.U = this.random.nextInt(12000); this.U = this.random.nextInt(12000);
this.H = new int['\u8000']; this.H = new int['\u8000'];
this.V = new ArrayList(); this.V = new ArrayList();
@ -1856,7 +1858,7 @@ public class World implements IBlockAccess {
} }
protected void k() { protected void k() {
this.T.clear(); // this.T.clear(); // CraftBukkit -- removed
// MethodProfiler.a("buildList"); // CraftBukkit -- not in production code // MethodProfiler.a("buildList"); // CraftBukkit -- not in production code
int i; int i;
@ -1870,7 +1872,7 @@ public class World implements IBlockAccess {
for (j = -b0; j <= b0; ++j) { for (j = -b0; j <= b0; ++j) {
for (int i1 = -b0; i1 <= b0; ++i1) { for (int i1 = -b0; i1 <= b0; ++i1) {
this.T.add(new ChunkCoordIntPair(j + k, i1 + l)); this.T.add(LongHash.toLong(j + k, i1 + l)); // CraftBukkit
} }
} }
} }
@ -1883,15 +1885,19 @@ public class World implements IBlockAccess {
int j1 = 0; int j1 = 0;
// MethodProfiler.a(); // CraftBukkit -- not in production code // MethodProfiler.a(); // CraftBukkit -- not in production code
Iterator iterator = this.T.iterator(); // Iterator iterator = this.T.iterator(); CraftBukkit == removed
while (iterator.hasNext()) { // CraftBukkit start
ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next(); for (long chunkCoord : this.T.popAll()) {
int k1 = chunkcoordintpair.x * 16; int chunkX = LongHash.msw(chunkCoord);
int chunkZ = LongHash.lsw(chunkCoord);
// ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) iterator.next();
int k1 = chunkX * 16;
j = chunkcoordintpair.z * 16; j = chunkZ * 16;
// MethodProfiler.a("getChunk"); // CraftBukkit -- not in production code // MethodProfiler.a("getChunk"); // CraftBukkit -- not in production code
Chunk chunk = this.getChunkAt(chunkcoordintpair.x, chunkcoordintpair.z); Chunk chunk = this.getChunkAt(chunkX, chunkZ);
// CraftBukkit end
// MethodProfiler.b("tickChunk"); // CraftBukkit -- not in production code // MethodProfiler.b("tickChunk"); // CraftBukkit -- not in production code
chunk.i(); chunk.i();

Datei anzeigen

@ -535,7 +535,7 @@ public final class CraftServer implements Server {
internal.worldMaps = console.worlds.get(0).worldMaps; internal.worldMaps = console.worlds.get(0).worldMaps;
internal.tracker = new EntityTracker(console, dimension); internal.tracker = new EntityTracker(console, internal); // CraftBukkit
internal.addIWorldAccess((IWorldAccess) new WorldManager(console, internal)); internal.addIWorldAccess((IWorldAccess) new WorldManager(console, internal));
internal.difficulty = 1; internal.difficulty = 1;
internal.setSpawnFlags(true, true); internal.setSpawnFlags(true, true);

Datei anzeigen

@ -0,0 +1,8 @@
package org.bukkit.craftbukkit.util;
public class EntryBase {
protected long key;
public EntryBase(long key) {
this.key = key;
}
}

Datei anzeigen

@ -0,0 +1,115 @@
package org.bukkit.craftbukkit.util;
import net.minecraft.server.Chunk;
import net.minecraft.server.MinecraftServer;
import java.util.ArrayList;
import static org.bukkit.craftbukkit.util.Java15Compat.Arrays_copyOf;
public abstract class LongAbstractHashtable extends LongHash {
EntryBase[][][] values = new EntryBase[256][][];
EntryBase cache = null;
public void put(int msw, int lsw, EntryBase entry) {
put(entry);
}
public EntryBase getEntry(int msw, int lsw) {
return getEntry(toLong(msw, lsw));
}
public synchronized void put(EntryBase entry) {
int mainIdx = (int) (entry.key & 255);
EntryBase[][] outer = this.values[mainIdx];
if (outer == null) this.values[mainIdx] = outer = new EntryBase[256][];
int outerIdx = (int) ((entry.key >> 32) & 255);
EntryBase[] inner = outer[outerIdx];
if (inner == null) {
outer[outerIdx] = inner = new EntryBase[5];
inner[0] = this.cache = entry;
} else {
int i;
for (i = 0; i < inner.length; i++) {
if (inner[i] == null || inner[i].key == entry.key) {
inner[i] = this.cache = entry;
return;
}
}
outer[outerIdx] = inner = Arrays_copyOf(inner, i + i);
inner[i] = entry;
}
}
public synchronized EntryBase getEntry(long key) {
return containsKey(key) ? cache : null;
}
public synchronized boolean containsKey(long key) {
if (this.cache != null && cache.key == key) return true;
int outerIdx = (int) ((key >> 32) & 255);
EntryBase[][] outer = this.values[(int) (key & 255)];
if (outer == null) return false;
EntryBase[] inner = outer[outerIdx];
if (inner == null) return false;
for (int i = 0; i < inner.length; i++) {
EntryBase e = inner[i];
if (e == null) {
return false;
} else if (e.key == key) {
this.cache = e;
return true;
}
}
return false;
}
public synchronized void remove(long key) {
EntryBase[][] outer = this.values[(int) (key & 255)];
if (outer == null) return;
EntryBase[] inner = outer[(int) ((key >> 32) & 255)];
if (inner == null) return;
for (int i = 0; i < inner.length; i++) {
if (inner[i] == null) continue;
if (inner[i].key == key) {
for (i++; i < inner.length; i++) {
if (inner[i] == null) break;
inner[i-1] = inner[i];
}
inner[i-1] = null;
this.cache = null;
return;
}
}
}
public synchronized ArrayList<EntryBase> entries() {
ArrayList<EntryBase> ret = new ArrayList<EntryBase>();
for (EntryBase[][] outer: this.values) {
if (outer == null) continue;
for (EntryBase[] inner: outer) {
if (inner == null) continue;
for (EntryBase entry: inner) {
if (entry == null) break;
ret.add(entry);
}
}
}
return ret;
}
}

Datei anzeigen

@ -1,15 +1,15 @@
package org.bukkit.craftbukkit.util; package org.bukkit.craftbukkit.util;
public abstract class LongHash { public abstract class LongHash {
static long toLong(int msw, int lsw) { public static long toLong(int msw, int lsw) {
return ((long) msw << 32) + lsw - Integer.MIN_VALUE; return ((long) msw << 32) + lsw - Integer.MIN_VALUE;
} }
static int msw(long l) { public static int msw(long l) {
return (int) (l >> 32); return (int) (l >> 32);
} }
static int lsw(long l) { public static int lsw(long l) {
return (int) (l & 0xFFFFFFFF) + Integer.MIN_VALUE; return (int) (l & 0xFFFFFFFF) + Integer.MIN_VALUE;
} }

Datei anzeigen

@ -125,6 +125,31 @@ public class LongHashset extends LongHash {
return 0; return 0;
} }
public long[] popAll() {
int index = 0;
rl.lock();
try {
long[] ret = new long[this.count];
for (long[][] outer: this.values) {
if (outer == null) continue;
for (int oIdx = outer.length - 1; oIdx >= 0; oIdx--) {
long[] inner = outer[oIdx];
if (inner == null) continue;
for (long entry: inner) {
ret[index++] = entry;
}
outer[oIdx] = null;
}
}
count = 0;
return ret;
} finally {
rl.unlock();
}
}
public long[] keys() { public long[] keys() {
int index = 0; int index = 0;
rl.lock(); rl.lock();

Datei anzeigen

@ -5,136 +5,40 @@ import net.minecraft.server.Chunk;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import static org.bukkit.craftbukkit.util.Java15Compat.Arrays_copyOf; import static org.bukkit.craftbukkit.util.Java15Compat.Arrays_copyOf;
public class LongHashtable<V> extends LongHash { public class LongHashtable<V> extends LongAbstractHashtable {
Object[][][] values = new Object[256][][];
Entry cache = null;
public void put(int msw, int lsw, V value) { public void put(int msw, int lsw, V value) {
put(toLong(msw, lsw), value); put(toLong(msw, lsw), value);
if (value instanceof Chunk) {
Chunk c = (Chunk) value;
if (msw != c.x || lsw != c.z) {
MinecraftServer.log.info("Chunk (" + c.x + ", " + c.z + ") stored at (" + msw + ", " + lsw + ")");
Throwable x = new Throwable();
x.fillInStackTrace();
x.printStackTrace();
}
}
} }
public V get(int msw, int lsw) { public V get(int msw, int lsw) {
V value = get(toLong(msw, lsw)); return get(toLong(msw, lsw));
if (value instanceof Chunk) {
Chunk c = (Chunk) value;
if (msw != c.x || lsw != c.z) {
MinecraftServer.log.info("Chunk (" + c.x + ", " + c.z + ") stored at (" + msw + ", " + lsw + ")");
Throwable x = new Throwable();
x.fillInStackTrace();
x.printStackTrace();
}
}
return value;
} }
public synchronized void put(long key, V value) { public synchronized void put(long key, V value) {
int mainIdx = (int) (key & 255); put(new Entry(key, value));
Object[][] outer = this.values[mainIdx];
if (outer == null) this.values[mainIdx] = outer = new Object[256][];
int outerIdx = (int) ((key >> 32) & 255);
Object[] inner = outer[outerIdx];
if (inner == null) {
outer[outerIdx] = inner = new Object[5];
inner[0] = this.cache = new Entry(key, value);
} else {
int i;
for (i = 0; i < inner.length; i++) {
if (inner[i] == null || ((Entry) inner[i]).key == key) {
inner[i] = this.cache = new Entry(key, value);
return;
}
}
outer[outerIdx] = inner = Arrays_copyOf(inner, i + i);
inner[i] = new Entry(key, value);
}
} }
public synchronized V get(long key) { public synchronized V get(long key) {
return containsKey(key) ? (V) cache.value : null; Entry entry = ((Entry)getEntry(key));
} return entry != null ? entry.value : null;
public synchronized boolean containsKey(long key) {
if (this.cache != null && cache.key == key) return true;
int outerIdx = (int) ((key >> 32) & 255);
Object[][] outer = this.values[(int) (key & 255)];
if (outer == null) return false;
Object[] inner = outer[outerIdx];
if (inner == null) return false;
for (int i = 0; i < inner.length; i++) {
Entry e = (Entry) inner[i];
if (e == null) {
return false;
} else if (e.key == key) {
this.cache = e;
return true;
}
}
return false;
}
public synchronized void remove(long key) {
Object[][] outer = this.values[(int) (key & 255)];
if (outer == null) return;
Object[] inner = outer[(int) ((key >> 32) & 255)];
if (inner == null) return;
for (int i = 0; i < inner.length; i++) {
if (inner[i] == null) continue;
if (((Entry) inner[i]).key == key) {
for (i++; i < inner.length; i++) {
if (inner[i] == null) break;
inner[i-1] = inner[i];
}
inner[i-1] = null;
this.cache = null;
return;
}
}
} }
public synchronized ArrayList<V> values() { public synchronized ArrayList<V> values() {
ArrayList<V> ret = new ArrayList<V>(); ArrayList<V> ret = new ArrayList<V>();
for (Object[][] outer: this.values) { ArrayList<EntryBase> entries = entries();
if (outer == null) continue;
for (Object[] inner: outer) { for(EntryBase entry : entries) {
if (inner == null) continue; ret.add(((Entry)entry).value);
for (Object entry: inner) {
if (entry == null) break;
ret.add((V) ((Entry) entry).value);
}
}
} }
return ret; return ret;
} }
private class Entry { private class Entry extends EntryBase {
long key; V value;
Object value; Entry(long k, V v) {
super(k);
Entry(long k, Object v) {
this.key = k;
this.value = v; this.value = v;
} }
} }