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...
|
|
|
|
|
2024-12-16 10:43:57 +01:00
|
|
|
diff --git a/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
2024-12-16 15:17:46 +01:00
|
|
|
index d310e7489fc4ecede8deef59241444769d87b0a1..796b5f8541b0cf84482ab2b5a60adde544d43593 100644
|
2024-12-16 10:43:57 +01:00
|
|
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
|
|
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
|
|
|
@@ -218,6 +218,12 @@ public class ServerChunkCache extends ChunkSource {
|
|
|
|
if (Thread.currentThread() != this.mainThread) {
|
|
|
|
return CompletableFuture.<ChunkAccess>supplyAsync(() -> this.getChunk(x, z, chunkStatus, requireChunk), this.mainThreadProcessor).join();
|
2021-06-11 14:02:28 +02:00
|
|
|
} else {
|
2024-01-21 12:53:04 +01:00
|
|
|
+ // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
|
2024-12-16 11:34:20 +01:00
|
|
|
+ LevelChunk ifLoaded = this.getChunkAtIfCachedImmediately(x, z);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ if (ifLoaded != null) {
|
|
|
|
+ return ifLoaded;
|
|
|
|
+ }
|
2024-01-21 12:53:04 +01:00
|
|
|
+ // Paper end - Perf: Optimise getChunkAt calls for loaded chunks
|
2024-12-16 10:43:57 +01:00
|
|
|
ProfilerFiller profilerFiller = Profiler.get();
|
|
|
|
profilerFiller.incrementCounter("getChunk");
|
|
|
|
long packedChunkPos = ChunkPos.asLong(x, z);
|
|
|
|
@@ -252,30 +258,7 @@ public class ServerChunkCache extends ChunkSource {
|
2024-01-24 13:07:40 +01:00
|
|
|
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");
|
2024-12-16 10:43:57 +01:00
|
|
|
- long packedChunkPos = ChunkPos.asLong(chunkX, chunkZ);
|
2021-06-11 14:02:28 +02:00
|
|
|
-
|
2024-12-16 10:43:57 +01:00
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
|
- if (packedChunkPos == this.lastChunkPos[i] && this.lastChunkStatus[i] == ChunkStatus.FULL) {
|
|
|
|
- ChunkAccess chunkAccess = this.lastChunk[i];
|
|
|
|
- return chunkAccess instanceof LevelChunk ? (LevelChunk)chunkAccess : null;
|
2021-06-11 14:02:28 +02:00
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
2024-12-16 10:43:57 +01:00
|
|
|
- ChunkHolder visibleChunkIfPresent = this.getVisibleChunkIfPresent(packedChunkPos);
|
|
|
|
- if (visibleChunkIfPresent == null) {
|
2021-06-11 14:02:28 +02:00
|
|
|
- return null;
|
|
|
|
- } else {
|
2024-12-16 10:43:57 +01:00
|
|
|
- ChunkAccess chunkAccess = visibleChunkIfPresent.getChunkIfPresent(ChunkStatus.FULL);
|
|
|
|
- if (chunkAccess != null) {
|
|
|
|
- this.storeInCache(packedChunkPos, chunkAccess, ChunkStatus.FULL);
|
|
|
|
- if (chunkAccess instanceof LevelChunk) {
|
|
|
|
- return (LevelChunk)chunkAccess;
|
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
|
|
|
- }
|
2024-12-16 11:34:20 +01:00
|
|
|
+ return this.getChunkAtIfCachedImmediately(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
|
2021-06-11 14:02:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|