mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 11:06:29 +01:00
e5f6489602
This also cleans up the implementation of Async Chunks to get rid of most Consumer callbacks and instead return futures. This lets us propogate errors correctly up the future chain (barring one isn't lost even deeper in the chain...) So exceptions can now bubble to plugins using getChunkAtAsync
86 lines
3.7 KiB
Diff
86 lines
3.7 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/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
index cbaf14b24b3d941f0912788c87c3eab5aad7f5f0..ea85f40f4d40f687f3feaf161d2248f2bcc39af2 100644
|
|
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
|
|
@@ -434,6 +434,12 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
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");
|
|
@@ -484,39 +490,7 @@ public class ChunkProviderServer extends IChunkProvider {
|
|
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 {
|
|
- Either<IChunkAccess, PlayerChunk.Failure> either = (Either) playerchunk.b(ChunkStatus.FULL).getNow(null); // CraftBukkit - decompile error
|
|
-
|
|
- if (either == null) {
|
|
- return null;
|
|
- } else {
|
|
- IChunkAccess ichunkaccess1 = (IChunkAccess) either.left().orElse(null); // CraftBukkit - decompile error
|
|
-
|
|
- 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
|
|
index f1d072a39cc2f0f7b214e7794f8dc5dcc282d6b3..0c23fc89d7ad980aa8b094784e88e2d91fb4f07b 100644
|
|
--- a/src/main/java/net/minecraft/server/World.java
|
|
+++ b/src/main/java/net/minecraft/server/World.java
|
|
@@ -265,6 +265,14 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
|
|
|
|
@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);
|
|
}
|
|
|