PaperMC/patches/server/0309-Optimise-getChunkAt-calls-for-loaded-chunks.patch

61 lines
2.7 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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
2024-10-25 12:30:19 +02:00
index fef86453d5cf0fe0f11a2a061169cd301b777434..9ab43b4273975d7599f8eee2f95773f2984b7c37 100644
2021-06-11 14:02:28 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
2024-10-23 15:54:09 +02:00
@@ -191,6 +191,12 @@ public class ServerChunkCache extends ChunkSource {
2021-06-11 14:02:28 +02:00
return this.getChunk(x, z, leastStatus, create);
}, this.mainThreadProcessor).join();
} else {
+ // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
2021-06-11 14:02:28 +02:00
+ LevelChunk ifLoaded = this.getChunkAtIfLoadedMainThread(x, z);
+ if (ifLoaded != null) {
+ return ifLoaded;
+ }
+ // Paper end - Perf: Optimise getChunkAt calls for loaded chunks
2024-10-23 15:54:09 +02:00
ProfilerFiller gameprofilerfiller = Profiler.get();
2021-06-11 14:02:28 +02:00
gameprofilerfiller.incrementCounter("getChunk");
2024-10-23 15:54:09 +02:00
@@ -234,33 +240,7 @@ public class ServerChunkCache extends ChunkSource {
if (Thread.currentThread() != this.mainThread) {
2021-06-11 14:02:28 +02:00
return null;
} else {
2024-10-23 15:54:09 +02:00
- Profiler.get().incrementCounter("getChunkNow");
2021-06-11 14:02:28 +02:00
- long k = ChunkPos.asLong(chunkX, chunkZ);
-
2024-06-13 22:14:13 +02:00
- ChunkAccess ichunkaccess;
-
2021-06-11 14:02:28 +02:00
- for (int l = 0; l < 4; ++l) {
- if (k == this.lastChunkPos[l] && this.lastChunkStatus[l] == ChunkStatus.FULL) {
2024-06-13 22:14:13 +02:00
- ichunkaccess = this.lastChunk[l];
2021-06-11 14:02:28 +02:00
- return ichunkaccess instanceof LevelChunk ? (LevelChunk) ichunkaccess : null;
- }
- }
-
- ChunkHolder playerchunk = this.getVisibleChunkIfPresent(k);
-
- if (playerchunk == null) {
- return null;
- } else {
2024-06-13 22:14:13 +02:00
- ichunkaccess = playerchunk.getChunkIfPresent(ChunkStatus.FULL);
- if (ichunkaccess != null) {
- this.storeInCache(k, ichunkaccess, ChunkStatus.FULL);
- if (ichunkaccess instanceof LevelChunk) {
- return (LevelChunk) ichunkaccess;
2021-06-11 14:02:28 +02:00
- }
- }
2024-06-13 22:14:13 +02:00
-
- return null;
2021-06-11 14:02:28 +02:00
- }
+ return this.getChunkAtIfLoadedMainThread(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
2021-06-11 14:02:28 +02:00
}
}