Optimise Chunk#getFluid

Removing the try catch and generally reducing ops should make it
faster on its own, however removing the try catch makes it
easier to inline due to code size
This commit is contained in:
Spottedleaf 2020-01-14 14:59:08 -08:00
parent 05df94d332
commit 34933f9884
2 changed files with 57 additions and 17 deletions

View File

@ -86,7 +86,7 @@
int i = pos.getX(); int i = pos.getX();
int j = pos.getY(); int j = pos.getY();
int k = pos.getZ(); int k = pos.getZ();
@@ -243,7 +280,19 @@ @@ -243,24 +280,38 @@
} }
} }
@ -106,8 +106,36 @@
public FluidState getFluidState(BlockPos pos) { public FluidState getFluidState(BlockPos pos) {
return this.getFluidState(pos.getX(), pos.getY(), pos.getZ()); return this.getFluidState(pos.getX(), pos.getY(), pos.getZ());
} }
@@ -272,78 +321,86 @@
public FluidState getFluidState(int x, int y, int z) {
- try {
- int l = this.getSectionIndex(y);
-
- if (l >= 0 && l < this.sections.length) {
- LevelChunkSection chunksection = this.sections[l];
+ // Paper start - Perf: Optimise Chunk#getFluid
+ // try { // Remove try catch
+ int index = this.getSectionIndex(y);
+ if (index >= 0 && index < this.sections.length) {
+ LevelChunkSection chunksection = this.sections[index];
if (!chunksection.hasOnlyAir()) {
- return chunksection.getFluidState(x & 15, y & 15, z & 15);
+ return chunksection.states.get((y & 15) << 8 | (z & 15) << 4 | x & 15).getFluidState();
+ // Paper end - Perf: Optimise Chunk#getFluid
}
}
return Fluids.EMPTY.defaultFluidState();
+ /* // Paper - Perf: Optimise Chunk#getFluid
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Getting fluid state");
CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Block being got");
@@ -270,80 +321,89 @@
});
throw new ReportedException(crashreport);
} }
+ */ // Paper - Perf: Optimise Chunk#getFluid
} }
+ // CraftBukkit start + // CraftBukkit start
@ -218,7 +246,7 @@
this.updateBlockEntityTicker(tileentity); this.updateBlockEntityTicker(tileentity);
} }
} }
@@ -375,7 +432,12 @@ @@ -375,7 +435,12 @@
@Nullable @Nullable
public BlockEntity getBlockEntity(BlockPos pos, LevelChunk.EntityCreationType creationType) { public BlockEntity getBlockEntity(BlockPos pos, LevelChunk.EntityCreationType creationType) {
@ -232,7 +260,7 @@
if (tileentity == null) { if (tileentity == null) {
CompoundTag nbttagcompound = (CompoundTag) this.pendingBlockEntities.remove(pos); CompoundTag nbttagcompound = (CompoundTag) this.pendingBlockEntities.remove(pos);
@@ -446,7 +508,13 @@ @@ -446,7 +511,13 @@
BlockState iblockdata = this.getBlockState(blockposition); BlockState iblockdata = this.getBlockState(blockposition);
if (!iblockdata.hasBlockEntity()) { if (!iblockdata.hasBlockEntity()) {
@ -247,7 +275,7 @@
} else { } else {
BlockState iblockdata1 = blockEntity.getBlockState(); BlockState iblockdata1 = blockEntity.getBlockState();
@@ -500,6 +568,12 @@ @@ -500,6 +571,12 @@
if (this.isInLevel()) { if (this.isInLevel()) {
BlockEntity tileentity = (BlockEntity) this.blockEntities.remove(pos); BlockEntity tileentity = (BlockEntity) this.blockEntities.remove(pos);
@ -260,10 +288,14 @@
if (tileentity != null) { if (tileentity != null) {
Level world = this.level; Level world = this.level;
@@ -553,6 +627,65 @@ @@ -549,9 +626,68 @@
if (this.postLoad != null) {
} this.postLoad.run(this);
this.postLoad = null;
+ }
+
+ }
+
+ // CraftBukkit start + // CraftBukkit start
+ public void loadCallback() { + public void loadCallback() {
+ // Paper start + // Paper start
@ -301,7 +333,7 @@
+ } + }
+ server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk)); + server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
+ } + }
+ } }
+ } + }
+ +
+ public void unloadCallback() { + public void unloadCallback() {
@ -316,17 +348,16 @@
+ this.loadedTicketLevel = false; + this.loadedTicketLevel = false;
+ // Paper end + // Paper end
+ } + }
+
+ @Override + @Override
+ public boolean isUnsaved() { + public boolean isUnsaved() {
+ return super.isUnsaved() && !this.mustNotSave; + return super.isUnsaved() && !this.mustNotSave;
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
public boolean isEmpty() { public boolean isEmpty() {
return false; return false;
} @@ -750,7 +886,7 @@
@@ -750,7 +883,7 @@
private <T extends BlockEntity> void updateBlockEntityTicker(T blockEntity) { private <T extends BlockEntity> void updateBlockEntityTicker(T blockEntity) {
BlockState iblockdata = blockEntity.getBlockState(); BlockState iblockdata = blockEntity.getBlockState();
@ -335,7 +366,7 @@
if (blockentityticker == null) { if (blockentityticker == null) {
this.removeBlockEntityTicker(blockEntity.getBlockPos()); this.removeBlockEntityTicker(blockEntity.getBlockPos());
@@ -841,7 +974,7 @@ @@ -841,7 +977,7 @@
private boolean loggedInvalidBlockState; private boolean loggedInvalidBlockState;
BoundTickingBlockEntity(final BlockEntity tileentity, final BlockEntityTicker blockentityticker) { BoundTickingBlockEntity(final BlockEntity tileentity, final BlockEntityTicker blockentityticker) {
@ -344,7 +375,7 @@
this.ticker = blockentityticker; this.ticker = blockentityticker;
} }
@@ -867,11 +1000,13 @@ @@ -867,11 +1003,13 @@
gameprofilerfiller.pop(); gameprofilerfiller.pop();
} catch (Throwable throwable) { } catch (Throwable throwable) {

View File

@ -27,6 +27,15 @@
this.recalcBlockCounts(); this.recalcBlockCounts();
} }
@@ -49,7 +49,7 @@
}
public FluidState getFluidState(int x, int y, int z) {
- return ((BlockState) this.states.get(x, y, z)).getFluidState();
+ return this.states.get(x, y, z).getFluidState(); // Paper - Perf: Optimise Chunk#getFluid; diff on change - we expect this to be effectively just getType(x, y, z).getFluid(). If this changes we need to check other patches that use IBlockData#getFluid.
}
public void acquire() {
@@ -196,6 +196,12 @@ @@ -196,6 +196,12 @@
return (Holder) this.biomes.get(x, y, z); return (Holder) this.biomes.get(x, y, z);
} }