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

[Bleeding] Optimize chunk loading

ChunkSection.e() is called once per chunk section loaded and is quite
expensive (about 20% of CPU time for loading the chunk). This changes the
logic to add a fast path when extended block data is not being used and
reorganizes the loops for more optimal array traversal. Overall this saves
about 20-30% CPU time in this method.
Dieser Commit ist enthalten in:
Mike Primm 2012-08-09 01:10:12 -05:00 committet von Travis Watkins
Ursprung 852602e430
Commit 6d777ade16

Datei anzeigen

@ -111,6 +111,63 @@ public class ChunkSection {
} }
public void e() { public void e() {
// CraftBukkit start - optimize for speed
byte[] dd = this.d;
int cntb = 0;
int cntc = 0;
if (this.e == null) { // No extended block IDs? Don't waste time messing with them
for (int off = 0; off < dd.length; off++) {
int l = dd[off] & 0xFF;
if (l > 0) {
if (Block.byId[l] == null) {
dd[off] = 0;
} else {
++cntb;
if (Block.byId[l].r()) {
++cntc;
}
}
}
}
} else {
byte[] ext = this.e.a;
for (int off = 0, off2 = 0; off < dd.length;) {
byte extid = ext[off2];
int l = (dd[off] & 0xFF) | ((extid & 0xF) << 8); // Even data
if (l > 0) {
if (Block.byId[l] == null) {
dd[off] = 0;
ext[off2] &= 0xF0;
} else {
++cntb;
if (Block.byId[l].r()) {
++cntc;
}
}
}
off++;
l = (dd[off] & 0xFF) | ((extid & 0xF0) << 4); // Odd data
if (l > 0) {
if (Block.byId[l] == null) {
dd[off] = 0;
ext[off2] &= 0x0F;
} else {
++cntb;
if (Block.byId[l].r()) {
++cntc;
}
}
}
off++;
off2++;
}
}
this.b = cntb;
this.c = cntc;
}
private void old_e() {
// CraftBukkit end
this.b = 0; this.b = 0;
this.c = 0; this.c = 0;