mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 12:05:53 +01:00
c5a10665b8
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
62 lines
3.1 KiB
Diff
62 lines
3.1 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Tue, 14 Jan 2020 14:59:08 -0800
|
|
Subject: [PATCH] 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
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
index 6775217c065026aa61fce56a17c93010209b6941..59f9ff720e92c69e11afe7f6ccecd81b0e54a74d 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunk.java
|
|
@@ -270,18 +270,20 @@ public class LevelChunk extends ChunkAccess {
|
|
}
|
|
|
|
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");
|
|
@@ -291,6 +293,7 @@ public class LevelChunk extends ChunkAccess {
|
|
});
|
|
throw new ReportedException(crashreport);
|
|
}
|
|
+ */ // Paper - Perf: Optimise Chunk#getFluid
|
|
}
|
|
|
|
// CraftBukkit start
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
index 2c153af611399e884752f8256bee4fe32de5c572..90d1c3e23e753c29660f7d993b3c90ac022941c3 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/LevelChunkSection.java
|
|
@@ -43,7 +43,7 @@ public class LevelChunkSection {
|
|
}
|
|
|
|
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() {
|