mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
57 lines
2.8 KiB
Diff
57 lines
2.8 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/net/minecraft/server/level/ServerChunkCache.java b/net/minecraft/server/level/ServerChunkCache.java
|
|
index d310e7489fc4ecede8deef59241444769d87b0a1..f268808cb250e374f2d5652b20eece011e87dcfb 100644
|
|
--- 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();
|
|
} else {
|
|
+ // Paper start - Perf: Optimise getChunkAt calls for loaded chunks
|
|
+ LevelChunk ifLoaded = this.getChunkAtIfCachedImmediately(x, z);
|
|
+ if (ifLoaded != null) {
|
|
+ return ifLoaded;
|
|
+ }
|
|
+ // Paper end - Perf: Optimise getChunkAt calls for loaded chunks
|
|
ProfilerFiller profilerFiller = Profiler.get();
|
|
profilerFiller.incrementCounter("getChunk");
|
|
long packedChunkPos = ChunkPos.asLong(x, z);
|
|
@@ -252,30 +258,7 @@ public class ServerChunkCache extends ChunkSource {
|
|
if (Thread.currentThread() != this.mainThread) {
|
|
return null;
|
|
} else {
|
|
- Profiler.get().incrementCounter("getChunkNow");
|
|
- long packedChunkPos = ChunkPos.asLong(chunkX, chunkZ);
|
|
-
|
|
- 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;
|
|
- }
|
|
- }
|
|
-
|
|
- ChunkHolder visibleChunkIfPresent = this.getVisibleChunkIfPresent(packedChunkPos);
|
|
- if (visibleChunkIfPresent == null) {
|
|
- return null;
|
|
- } else {
|
|
- ChunkAccess chunkAccess = visibleChunkIfPresent.getChunkIfPresent(ChunkStatus.FULL);
|
|
- if (chunkAccess != null) {
|
|
- this.storeInCache(packedChunkPos, chunkAccess, ChunkStatus.FULL);
|
|
- if (chunkAccess instanceof LevelChunk) {
|
|
- return (LevelChunk)chunkAccess;
|
|
- }
|
|
- }
|
|
-
|
|
- return null;
|
|
- }
|
|
+ return this.getChunkAtIfCachedImmediately(chunkX, chunkZ); // Paper - Perf: Optimise getChunkAt calls for loaded chunks
|
|
}
|
|
}
|
|
|