Boost light task priority to ensure it doesnt hold up chunk loads

Run urgent as 2 so urgent light can run as 1 (light run at chunk -1 for loading purposes)
This commit is contained in:
Aikar 2020-06-03 01:46:09 -04:00
parent 3d2bc848c1
commit b75eeca0e5
No known key found for this signature in database
GPG key ID: 401ADFC9891FAAFE
2 changed files with 35 additions and 51 deletions

View file

@ -90,7 +90,7 @@ index f617636a22167b06ac8073aa25efd8c7099155f0..0f40793f004639822b9d40521cd21ec5
return new BlockPosition(this.x << 4, 0, this.z << 4);
}
diff --git a/src/main/java/net/minecraft/server/ChunkMapDistance.java b/src/main/java/net/minecraft/server/ChunkMapDistance.java
index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c9f0cca59 100644
index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..a4a4235f42de1876641a936469fbc65be3192c76 100644
--- a/src/main/java/net/minecraft/server/ChunkMapDistance.java
+++ b/src/main/java/net/minecraft/server/ChunkMapDistance.java
@@ -23,6 +23,7 @@ import java.util.concurrent.Executor;
@ -131,7 +131,7 @@ index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c
// Paper end
return true;
} else {
@@ -147,14 +152,16 @@ public abstract class ChunkMapDistance {
@@ -147,8 +152,10 @@ public abstract class ChunkMapDistance {
return flag;
}
}
@ -142,13 +142,6 @@ index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c
ArraySetSorted<Ticket<?>> arraysetsorted = this.e(i);
int j = a(arraysetsorted);
Ticket<?> ticket1 = (Ticket) arraysetsorted.a(ticket); // CraftBukkit - decompile error
ticket1.a(this.currentTick);
- if (ticket.b() < j) {
+ if (ticket.getTicketLevel() < j) {
this.e.b(i, ticket.b(), true);
}
@@ -162,6 +169,7 @@ public abstract class ChunkMapDistance {
}
@ -157,17 +150,18 @@ index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c
ArraySetSorted<Ticket<?>> arraysetsorted = this.e(i);
boolean removed = false; // CraftBukkit
@@ -182,6 +190,87 @@ public abstract class ChunkMapDistance {
@@ -182,6 +190,88 @@ public abstract class ChunkMapDistance {
this.addTicketAtLevel(tickettype, chunkcoordintpair, i, t0);
}
+ // Paper start
+ public static final int PRIORITY_TICKET_LEVEL = 33;
+ public static final int URGENT_PRIORITY = 29;
+ public boolean markUrgent(ChunkCoordIntPair coords) {
+ return addPriorityTicket(coords, TicketType.URGENT, 30);
+ return addPriorityTicket(coords, TicketType.URGENT, URGENT_PRIORITY);
+ }
+ public boolean markHighPriority(ChunkCoordIntPair coords, int priority) {
+ priority = Math.min(28, Math.max(1, priority));
+ priority = Math.min(URGENT_PRIORITY - 1, Math.max(1, priority));
+ return addPriorityTicket(coords, TicketType.PRIORITY, priority);
+ }
+
@ -221,7 +215,7 @@ index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c
+ }
+ for (Ticket<?> ticket : tickets) {
+ if (ticket.getTicketType() == TicketType.URGENT) {
+ return 30;
+ return URGENT_PRIORITY;
+ }
+ }
+ for (Ticket<?> ticket : tickets) {
@ -245,7 +239,7 @@ index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c
public <T> boolean addTicketAtLevel(TicketType<T> ticketType, ChunkCoordIntPair chunkcoordintpair, int level, T identifier) {
return this.addTicket(chunkcoordintpair.pair(), new Ticket<>(ticketType, level, identifier));
// CraftBukkit end
@@ -386,7 +475,32 @@ public abstract class ChunkMapDistance {
@@ -386,7 +476,32 @@ public abstract class ChunkMapDistance {
if (flag1) {
ChunkMapDistance.this.j.a(ChunkTaskQueueSorter.a(() -> { // CraftBukkit - decompile error
@ -279,7 +273,7 @@ index 586a20fe5c77c2ad5fa26f337a94a16e21d8b5e2..8a319f6e603f09567fc34d5c0150468c
if (this.c(this.c(i))) {
ChunkMapDistance.this.addTicket(i, ticket);
ChunkMapDistance.this.l.add(i);
@@ -397,12 +511,15 @@ public abstract class ChunkMapDistance {
@@ -397,12 +512,15 @@ public abstract class ChunkMapDistance {
});
}, i, () -> {
@ -399,7 +393,7 @@ index 07a6fc3d88e7d44bfab7f3d6a0eef7dc132ab422..c88177b77607519453bb349a8e960d22
for (int i = 0; i < this.inventory.getSize(); ++i) {
ItemStack itemstack = this.inventory.getItem(i);
diff --git a/src/main/java/net/minecraft/server/LightEngineThreaded.java b/src/main/java/net/minecraft/server/LightEngineThreaded.java
index 8776799de033f02b0f87e9ea7e4a4ce912e94dd4..402f305c8bd3de1d9b288dcc91a1a70324f37fed 100644
index 8776799de033f02b0f87e9ea7e4a4ce912e94dd4..e16eac92d072cbb3a6a4934e336898f5b8ca0658 100644
--- a/src/main/java/net/minecraft/server/LightEngineThreaded.java
+++ b/src/main/java/net/minecraft/server/LightEngineThreaded.java
@@ -134,7 +134,11 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
@ -409,7 +403,7 @@ index 8776799de033f02b0f87e9ea7e4a4ce912e94dd4..402f305c8bd3de1d9b288dcc91a1a703
- this.a(chunkcoordintpair.x, chunkcoordintpair.z, LightEngineThreaded.Update.PRE_UPDATE, SystemUtils.a(() -> {
+ // Paper start
+ IntSupplier defSupplier = this.d.c(chunkcoordintpair.pair());
+ IntSupplier priority = () -> Math.max(defSupplier.getAsInt() - (flag ? 2 : 0), 1);
+ IntSupplier priority = () -> Math.max(defSupplier.getAsInt() - 1, 1);
+ // Paper end
+ this.a(chunkcoordintpair.x, chunkcoordintpair.z, priority, LightEngineThreaded.Update.PRE_UPDATE, SystemUtils.a(() -> { // Paper - boost light priority
ChunkSection[] achunksection = ichunkaccess.getSections();
@ -437,7 +431,7 @@ index 0d1065688b19ceca9440bc8bf2bf65910f03fa46..8a349964578e07e5ed13f801c57de684
chunkData.addProperty("queued-for-unload", chunkMap.unloadQueue.contains(playerChunk.location.pair()));
chunkData.addProperty("status", status == null ? "unloaded" : status.toString());
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a30fe4d315 100644
index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..e490866b3f4ac846c5988f5bc564e3902c3786d3 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -26,8 +26,8 @@ public class PlayerChunk {
@ -459,7 +453,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
long lastAutoSaveTime; // Paper - incremental autosave
long inactiveTimeStart; // Paper - incremental autosave
@@ -67,6 +68,133 @@ public class PlayerChunk {
@@ -67,6 +68,124 @@ public class PlayerChunk {
return null;
}
// Paper end - no-tick view distance
@ -481,8 +475,8 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
+ }
+
+ private int getMyPriority() {
+ if (priorityBoost == 30) {
+ return 1; // Urgent - ticket level isn't always 31 so 33-30 = 3
+ if (priorityBoost == ChunkMapDistance.URGENT_PRIORITY) {
+ return 2; // Urgent - ticket level isn't always 31 so 33-30 = 3, but allow 1 more tasks to go below this for dependents
+ }
+ int basePriority = ticketLevel - priorityBoost;
+ if (ticketLevel >= 33 && priorityBoost == 0 && (neighborPriority >= 34 || neighborPriorities.isEmpty())) {
@ -555,15 +549,6 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
+ if (getCurrentPriority() != getDemandedPriority()) this.chunkMap.queueHolderUpdate(this);
+ }
+
+ public final double getDistanceFromPointInFront(EntityPlayer player, int dist) {
+ int inFront = dist * 16;
+ final float yaw = MCUtil.normalizeYaw(player.yaw);
+ double rads = Math.toRadians(yaw);
+ final double x = player.locX() + inFront * Math.cos(rads);
+ final double z = player.locZ() + inFront * Math.sin(rads);
+ return getDistance(x, z);
+ }
+
+ public final double getDistance(EntityPlayer player) {
+ return getDistance(player.locX(), player.locZ());
+ }
@ -593,7 +578,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
public PlayerChunk(ChunkCoordIntPair chunkcoordintpair, int i, LightEngine lightengine, PlayerChunk.c playerchunk_c, PlayerChunk.d playerchunk_d) {
this.statusFutures = new AtomicReferenceArray(PlayerChunk.CHUNK_STATUSES.size());
@@ -165,6 +293,15 @@ public class PlayerChunk {
@@ -165,6 +284,15 @@ public class PlayerChunk {
}
return null;
}
@ -609,7 +594,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
// Paper end
public CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> getStatusFutureUnchecked(ChunkStatus chunkstatus) {
@@ -418,6 +555,7 @@ public class PlayerChunk {
@@ -418,6 +546,7 @@ public class PlayerChunk {
return this.n;
}
@ -617,7 +602,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
private void d(int i) {
this.n = i;
}
@@ -436,7 +574,7 @@ public class PlayerChunk {
@@ -436,7 +565,7 @@ public class PlayerChunk {
// CraftBukkit start
// ChunkUnloadEvent: Called before the chunk is unloaded: isChunkLoaded is still true and chunk can still be modified by plugins.
if (playerchunk_state.isAtLeast(PlayerChunk.State.BORDER) && !playerchunk_state1.isAtLeast(PlayerChunk.State.BORDER)) {
@ -626,7 +611,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
Chunk chunk = (Chunk)either.left().orElse(null);
if (chunk != null) {
playerchunkmap.callbackExecutor.execute(() -> {
@@ -501,12 +639,13 @@ public class PlayerChunk {
@@ -501,12 +630,13 @@ public class PlayerChunk {
if (!flag2 && flag3) {
// Paper start - cache ticking ready status
int expectCreateCount = ++this.fullChunkCreateCount;
@ -641,7 +626,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
}
@@ -531,7 +670,7 @@ public class PlayerChunk {
@@ -531,7 +661,7 @@ public class PlayerChunk {
if (!flag4 && flag5) {
// Paper start - cache ticking ready status
@ -650,7 +635,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
if (either.left().isPresent()) {
// note: Here is a very good place to add callbacks to logic waiting on this.
Chunk tickingChunk = either.left().get();
@@ -562,7 +701,7 @@ public class PlayerChunk {
@@ -562,7 +692,7 @@ public class PlayerChunk {
}
// Paper start - cache ticking ready status
@ -659,7 +644,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
if (either.left().isPresent()) {
// note: Here is a very good place to add callbacks to logic waiting on this.
Chunk entityTickingChunk = either.left().get();
@@ -581,13 +720,29 @@ public class PlayerChunk {
@@ -581,13 +711,29 @@ public class PlayerChunk {
this.entityTickingFuture.complete(PlayerChunk.UNLOADED_CHUNK); this.isEntityTickingReady = false; // Paper - cache chunk ticking stage
this.entityTickingFuture = PlayerChunk.UNLOADED_CHUNK_FUTURE;
}
@ -692,7 +677,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
Chunk chunk = (Chunk)either.left().orElse(null);
if (chunk != null) {
playerchunkmap.callbackExecutor.execute(() -> {
@@ -669,6 +824,7 @@ public class PlayerChunk {
@@ -669,6 +815,7 @@ public class PlayerChunk {
public interface c {
@ -701,7 +686,7 @@ index aeca6b2b9d5d73aeb6dc639b5cad2f2533a2de44..885992d5d3bbe175ad4a8d1c875c68a3
}
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16fce9504fc 100644
index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..302db2ca5149c30dec9fd39d1bf4fd23d53587c7 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -50,6 +50,7 @@ import org.apache.commons.lang3.mutable.MutableBoolean;
@ -746,12 +731,11 @@ index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16f
this.playerViewDistanceNoTickMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets);
this.playerViewDistanceBroadcastMap = new com.destroystokyo.paper.util.misc.PlayerAreaMap(this.pooledLinkedPlayerHashSets,
(EntityPlayer player, int rangeX, int rangeZ, int currPosX, int currPosZ, int prevPosX, int prevPosZ,
@@ -410,6 +415,103 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -410,6 +415,102 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
});
// Paper end - no-tick view distance
}
+ // Paper start - Chunk Prioritization
+ private static final int[][] neighborMatrix = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};
+ public void queueHolderUpdate(PlayerChunk playerchunk) {
+ Runnable runnable = () -> {
+ if (isUnloading(playerchunk)) {
@ -831,7 +815,7 @@ index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16f
+
+ // Prioritize immediate
+ if (dist <= dist3Sq) {
+ chunkDistanceManager.markHighPriority(coord, (int) (28 - dist));
+ chunkDistanceManager.markHighPriority(coord, (int) (27 - dist));
+ return;
+ }
+
@ -850,7 +834,7 @@ index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16f
public void updatePlayerMobTypeMap(Entity entity) {
if (!this.world.paperConfig.perPlayerMobSpawns) {
@@ -539,6 +641,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -539,6 +640,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
List<CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>>> list = Lists.newArrayList();
int j = chunkcoordintpair.x;
int k = chunkcoordintpair.z;
@ -858,7 +842,7 @@ index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16f
for (int l = -i; l <= i; ++l) {
for (int i1 = -i; i1 <= i; ++i1) {
@@ -557,6 +660,14 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -557,6 +659,14 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
ChunkStatus chunkstatus = (ChunkStatus) intfunction.apply(j1);
CompletableFuture<Either<IChunkAccess, PlayerChunk.Failure>> completablefuture = playerchunk.a(chunkstatus, this);
@ -873,7 +857,7 @@ index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16f
list.add(completablefuture);
}
@@ -1022,14 +1133,22 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -1022,14 +1132,22 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
};
CompletableFuture<NBTTagCompound> chunkSaveFuture = this.world.asyncChunkTaskManager.getChunkSaveFuture(chunkcoordintpair.x, chunkcoordintpair.z);
@ -901,7 +885,7 @@ index 0aa14bfca6e1845eb6e9f5bd4e0e36335fa7f532..519ecdf76ba506f135aa668a3088a16f
return ret;
// Paper end
}
@@ -1158,7 +1277,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -1158,7 +1276,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
long i = playerchunk.i().pair();
playerchunk.getClass();

View file

@ -36,7 +36,7 @@ scenario / path:
Previously would have hopped to SERVER around 12+ times there extra.
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index 885992d5d3bbe175ad4a8d1c875c68a30fe4d315..01b7ac1b26461734d2b812a32fe95168bdc9d5c4 100644
index e490866b3f4ac846c5988f5bc564e3902c3786d3..b8631019b36aedb7b54a1e8852b911029cbe9af0 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -56,6 +56,13 @@ public class PlayerChunk {
@ -54,7 +54,7 @@ index 885992d5d3bbe175ad4a8d1c875c68a30fe4d315..01b7ac1b26461734d2b812a32fe95168
// Paper start - no-tick view distance
public final Chunk getSendingChunk() {
diff --git a/src/main/java/net/minecraft/server/PlayerChunkMap.java b/src/main/java/net/minecraft/server/PlayerChunkMap.java
index 519ecdf76ba506f135aa668a3088a16fce9504fc..142d6fac11236e2cfb3730aedf65ae08ae248b25 100644
index 302db2ca5149c30dec9fd39d1bf4fd23d53587c7..c5b5aaf4dd087dc87ecef08be4c8170f10e96b54 100644
--- a/src/main/java/net/minecraft/server/PlayerChunkMap.java
+++ b/src/main/java/net/minecraft/server/PlayerChunkMap.java
@@ -88,6 +88,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@ -81,7 +81,7 @@ index 519ecdf76ba506f135aa668a3088a16fce9504fc..142d6fac11236e2cfb3730aedf65ae08
ThreadedMailbox<Runnable> threadedmailbox = ThreadedMailbox.a(executor, "worldgen");
iasynctaskhandler.getClass();
@@ -708,7 +718,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -707,7 +717,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
return either.mapLeft((list) -> {
return (Chunk) list.get(list.size() / 2);
});
@ -90,7 +90,7 @@ index 519ecdf76ba506f135aa668a3088a16fce9504fc..142d6fac11236e2cfb3730aedf65ae08
}
@Nullable
@@ -1074,7 +1084,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -1073,7 +1083,7 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
return this.b(playerchunk, chunkstatus);
}
}
@ -99,7 +99,7 @@ index 519ecdf76ba506f135aa668a3088a16fce9504fc..142d6fac11236e2cfb3730aedf65ae08
}
}
@@ -1185,6 +1195,12 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
@@ -1184,6 +1194,12 @@ public class PlayerChunkMap extends IChunkLoader implements PlayerChunk.d {
return CompletableFuture.completedFuture(Either.right(playerchunk_failure));
});
}, (runnable) -> {