2020-05-06 09:48:49 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2020-01-28 00:16:53 +00:00
|
|
|
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/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2020-08-25 02:22:08 +00:00
|
|
|
index dce9c62c0cf37a37994537b74dfdc2286c60fae2..f7055ee0f2d497502f6a8b03544a55956f49e647 100644
|
2020-01-28 00:16:53 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
2020-08-25 02:22:08 +00:00
|
|
|
@@ -448,6 +448,12 @@ public class ChunkProviderServer extends IChunkProvider {
|
2020-01-28 00:16:53 +00:00
|
|
|
return this.getChunkAt(i, j, chunkstatus, flag);
|
|
|
|
}, this.serverThreadQueue).join();
|
|
|
|
} else {
|
|
|
|
+ // Paper start - optimise for loaded chunks
|
|
|
|
+ Chunk ifLoaded = this.getChunkAtIfLoadedMainThread(i, j);
|
|
|
|
+ if (ifLoaded != null) {
|
|
|
|
+ return ifLoaded;
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
GameProfilerFiller gameprofilerfiller = this.world.getMethodProfiler();
|
|
|
|
|
|
|
|
gameprofilerfiller.c("getChunk");
|
2020-08-25 02:22:08 +00:00
|
|
|
@@ -498,39 +504,7 @@ public class ChunkProviderServer extends IChunkProvider {
|
2020-01-28 00:16:53 +00:00
|
|
|
if (Thread.currentThread() != this.serverThread) {
|
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
- this.world.getMethodProfiler().c("getChunkNow");
|
|
|
|
- long k = ChunkCoordIntPair.pair(i, j);
|
|
|
|
-
|
|
|
|
- for (int l = 0; l < 4; ++l) {
|
|
|
|
- if (k == this.cachePos[l] && this.cacheStatus[l] == ChunkStatus.FULL) {
|
|
|
|
- IChunkAccess ichunkaccess = this.cacheChunk[l];
|
|
|
|
-
|
|
|
|
- return ichunkaccess instanceof Chunk ? (Chunk) ichunkaccess : null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- PlayerChunk playerchunk = this.getChunk(k);
|
|
|
|
-
|
|
|
|
- if (playerchunk == null) {
|
|
|
|
- return null;
|
|
|
|
- } else {
|
2020-02-02 11:53:48 +00:00
|
|
|
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
|
2020-01-28 00:16:53 +00:00
|
|
|
-
|
|
|
|
- if (either == null) {
|
|
|
|
- return null;
|
|
|
|
- } else {
|
2020-02-02 11:53:48 +00:00
|
|
|
- IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
|
2020-01-28 00:16:53 +00:00
|
|
|
-
|
|
|
|
- if (ichunkaccess1 != null) {
|
|
|
|
- this.a(k, ichunkaccess1, ChunkStatus.FULL);
|
|
|
|
- if (ichunkaccess1 instanceof Chunk) {
|
|
|
|
- return (Chunk) ichunkaccess1;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return null;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
+ return this.getChunkAtIfLoadedMainThread(i, j); // Paper - optimise for loaded chunks
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
|
2020-08-31 12:30:51 +00:00
|
|
|
index 8afacfb8d5f4efd2ad6f95fbb7b0d62e68c51503..b68ffde49d9f49a2c5e47b524d1db720b9d7f4eb 100644
|
2020-01-28 00:16:53 +00:00
|
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
2020-08-25 02:22:08 +00:00
|
|
|
@@ -286,6 +286,14 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
2020-01-28 00:16:53 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Chunk getChunkAt(int i, int j) {
|
|
|
|
+ // Paper start - optimise this for loaded chunks
|
|
|
|
+ if (Thread.currentThread() == this.serverThread) {
|
|
|
|
+ Chunk ifLoaded = ((WorldServer) this).getChunkProvider().getChunkAtIfLoadedMainThread(i, j);
|
|
|
|
+ if (ifLoaded != null) {
|
|
|
|
+ return ifLoaded;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
return (Chunk) this.getChunkAt(i, j, ChunkStatus.FULL);
|
|
|
|
}
|
|
|
|
|