mirror of
https://github.com/PaperMC/Paper.git
synced 2025-05-27 16:30:56 +00:00
Co-authored-by: Bjarne Koll <git@lynxplay.dev> Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com> Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Co-authored-by: MiniDigger | Martin <admin@minidigger.dev> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: Noah van der Aa <ndvdaa@gmail.com> Co-authored-by: Owen1212055 <23108066+Owen1212055@users.noreply.github.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Spottedleaf <Spottedleaf@users.noreply.github.com> Co-authored-by: Tamion <70228790+notTamion@users.noreply.github.com> Co-authored-by: Warrior <50800980+Warriorrrr@users.noreply.github.com>
58 lines
2.8 KiB
Diff
58 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 006d8abe66b2d66740b984d8ff7f56a41b9929f7..52104bcd74107bb9a475109230ca85dd2eba5b06 100644
|
|
--- a/net/minecraft/server/level/ServerChunkCache.java
|
|
+++ b/net/minecraft/server/level/ServerChunkCache.java
|
|
@@ -224,6 +224,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);
|
|
@@ -258,30 +264,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
|
|
}
|
|
}
|
|
|