mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 10:35:38 +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.
61 lines
2.7 KiB
Diff
61 lines
2.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Spottedleaf <Spottedleaf@users.noreply.github.com>
|
|
Date: Sat, 25 Jan 2020 17:04:35 -0800
|
|
Subject: [PATCH] Optimise getChunkAt calls for loaded chunks
|
|
|
|
bypass the need to get a player chunk, then get the either,
|
|
then unwrap it...
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
index a939bad7da9c852827a2d67d9ace5d0df4911a31..1049452baaf0381ffbf15b30da956c2a1994da35 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -179,6 +179,12 @@ public class ServerChunkCache extends ChunkSource {
|
|
return this.getChunk(x, z, leastStatus, create);
|
|
}, this.mainThreadProcessor).join();
|
|
} else {
|
|
+ // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
|
|
+ LevelChunk ifLoaded = this.getChunkAtIfLoadedMainThread(x, z);
|
|
+ if (ifLoaded != null) {
|
|
+ return ifLoaded;
|
|
+ }
|
|
+ // Paper end - Perf: Optimise getChunkAt calls for loaded chunks
|
|
ProfilerFiller gameprofilerfiller = this.level.getProfiler();
|
|
|
|
gameprofilerfiller.incrementCounter("getChunk");
|
|
@@ -222,33 +228,7 @@ public class ServerChunkCache extends ChunkSource {
|
|
if (Thread.currentThread() != this.mainThread) {
|
|
return null;
|
|
} else {
|
|
- this.level.getProfiler().incrementCounter("getChunkNow");
|
|
- long k = ChunkPos.asLong(chunkX, chunkZ);
|
|
-
|
|
- ChunkAccess ichunkaccess;
|
|
-
|
|
- for (int l = 0; l < 4; ++l) {
|
|
- if (k == this.lastChunkPos[l] && this.lastChunkStatus[l] == ChunkStatus.FULL) {
|
|
- ichunkaccess = this.lastChunk[l];
|
|
- return ichunkaccess instanceof LevelChunk ? (LevelChunk) ichunkaccess : null;
|
|
- }
|
|
- }
|
|
-
|
|
- ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k);
|
|
-
|
|
- if (playerchunk == null) {
|
|
- return null;
|
|
- } else {
|
|
- ichunkaccess = playerchunk.getChunkIfPresent(ChunkStatus.FULL);
|
|
- if (ichunkaccess != null) {
|
|
- this.storeInCache(k, ichunkaccess, ChunkStatus.FULL);
|
|
- if (ichunkaccess instanceof LevelChunk) {
|
|
- return (LevelChunk) ichunkaccess;
|
|
- }
|
|
- }
|
|
-
|
|
- return null;
|
|
- }
|
|
+ return this.getChunkAtIfLoadedMainThread(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
|
|
}
|
|
}
|
|
|