diff options
author | Mike Primm <mike@primmhome.com> | 2012-08-09 01:10:12 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2012-08-19 09:50:45 -0500 |
commit | 6d777ade166a5543a293c9353d7e6910b4a52b17 (patch) | |
tree | b9674f655b89936e6bc39cfb02aff460f44ad410 /src/main | |
parent | 852602e430f94a1ce627afd8de1599f2e804d788 (diff) | |
download | craftbukkit-6d777ade166a5543a293c9353d7e6910b4a52b17.tar craftbukkit-6d777ade166a5543a293c9353d7e6910b4a52b17.tar.gz craftbukkit-6d777ade166a5543a293c9353d7e6910b4a52b17.tar.lz craftbukkit-6d777ade166a5543a293c9353d7e6910b4a52b17.tar.xz craftbukkit-6d777ade166a5543a293c9353d7e6910b4a52b17.zip |
[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.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/net/minecraft/server/ChunkSection.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/net/minecraft/server/ChunkSection.java b/src/main/java/net/minecraft/server/ChunkSection.java index 4d38de8a..4891baf7 100644 --- a/src/main/java/net/minecraft/server/ChunkSection.java +++ b/src/main/java/net/minecraft/server/ChunkSection.java @@ -111,6 +111,63 @@ public class ChunkSection { } 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.c = 0; |