3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 11:00:06 +01:00

Light improvements

Trying to solve random hangs we've seen, ensuring that this part of code isnt the culprit

also fixing a vanilla bug reportedby PhiPro where tickets are released too early
hoping this reduces amount of incorrect light issues.
Dieser Commit ist enthalten in:
Aikar 2020-09-19 14:04:25 -04:00
Ursprung e3e1191ac9
Commit 826e09f369
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 401ADFC9891FAAFE

Datei anzeigen

@ -1027,7 +1027,7 @@ index a35e7b392c74fadf2760d1fc2021e98d33858cb5..944094e8e770cc8c0205ef2aa6c48fff
lightenginelayer.a(Long.MAX_VALUE, l3, 15, false);
}
diff --git a/src/main/java/net/minecraft/server/LightEngineThreaded.java b/src/main/java/net/minecraft/server/LightEngineThreaded.java
index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb726b95b6 100644
index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..fd0beefb900c064d3c35a3d2f79f5b7d9c1287bb 100644
--- a/src/main/java/net/minecraft/server/LightEngineThreaded.java
+++ b/src/main/java/net/minecraft/server/LightEngineThreaded.java
@@ -1,6 +1,7 @@
@ -1038,7 +1038,7 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import it.unimi.dsi.fastutil.objects.ObjectList;
import it.unimi.dsi.fastutil.objects.ObjectListIterator;
@@ -15,15 +16,158 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
@@ -15,15 +16,149 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
private static final Logger LOGGER = LogManager.getLogger();
private final ThreadedMailbox<Runnable> b;
@ -1048,7 +1048,7 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
+ private static final int MAX_PRIORITIES = PlayerChunkMap.GOLDEN_TICKET + 2;
+
+ private boolean isChunkLightStatus(long pair) {
+ PlayerChunk playerChunk = playerChunkMap.getUpdatingChunk(pair);
+ PlayerChunk playerChunk = playerChunkMap.getVisibleChunk(pair);
+ if (playerChunk == null) {
+ return false;
+ }
@ -1084,7 +1084,6 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
+ // Retain the chunks priority level for queued light tasks
+ class LightQueue {
+ private int size = 0;
+ private int lowestPriority = MAX_PRIORITIES;
+ private final Long2ObjectLinkedOpenHashMap<ChunkLightQueue>[] buckets = new Long2ObjectLinkedOpenHashMap[MAX_PRIORITIES];
+ private final java.util.concurrent.ConcurrentLinkedQueue<PendingLightTask> pendingTasks = new java.util.concurrent.ConcurrentLinkedQueue<>();
+ private final java.util.concurrent.ConcurrentLinkedQueue<Runnable> priorityChanges = new java.util.concurrent.ConcurrentLinkedQueue<>();
@ -1105,11 +1104,6 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
+ remove.post.addAll(existing.post);
+ }
+ }
+ if (!this.buckets[priority].isEmpty()) {
+ if (lowestPriority > priority) {
+ lowestPriority = priority;
+ }
+ }
+ });
+ }
+
@ -1136,10 +1130,6 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
+ if (update.fastUpdate) {
+ lightQueue.shouldFastUpdate = true;
+ }
+
+ if (this.lowestPriority > priority) {
+ this.lowestPriority = priority;
+ }
+ }
+
+ public final boolean isEmpty() {
@ -1161,11 +1151,12 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
+ }
+ boolean hasWork = false;
+ Long2ObjectLinkedOpenHashMap<ChunkLightQueue>[] buckets = this.buckets;
+ int lowestPriority = 0;
+ while (lowestPriority < MAX_PRIORITIES && !isEmpty()) {
+ Long2ObjectLinkedOpenHashMap<ChunkLightQueue> bucket = buckets[lowestPriority];
+ if (bucket.isEmpty()) {
+ lowestPriority++;
+ if (hasWork && lowestPriority <= 3) {
+ if (hasWork && lowestPriority <= 5) {
+ return true;
+ } else {
+ continue;
@ -1200,7 +1191,7 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
this.e = mailbox;
this.b = threadedmailbox;
}
@@ -110,13 +254,9 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
@@ -110,13 +245,9 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
}
private void a(int i, int j, IntSupplier intsupplier, LightEngineThreaded.Update lightenginethreaded_update, Runnable runnable) {
@ -1217,7 +1208,7 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
}
@Override
@@ -133,8 +273,20 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
@@ -133,8 +264,19 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
public CompletableFuture<IChunkAccess> a(IChunkAccess ichunkaccess, boolean flag) {
ChunkCoordIntPair chunkcoordintpair = ichunkaccess.getPos();
@ -1231,7 +1222,6 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
+ boolean[] skippedPre = {false};
+ this.queue.addChunk(pair, prioritySupplier, SystemUtils.a(() -> {
+ if (!isChunkLightStatus(pair)) {
+ this.d.c(chunkcoordintpair); // copied from end of method to release light ticket
+ future.complete(ichunkaccess);
+ skippedPre[0] = true;
+ return;
@ -1240,18 +1230,19 @@ index f8c2b957bb5b38f05251cccf5137a9c23262c3d6..ec8498c3db7a8d417f27eed5d3af38cb
ChunkSection[] achunksection = ichunkaccess.getSections();
for (int i = 0; i < 16; ++i) {
@@ -152,55 +304,47 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
@@ -152,55 +294,48 @@ public class LightEngineThreaded extends LightEngine implements AutoCloseable {
});
}
- this.d.c(chunkcoordintpair);
+ this.d.c(chunkcoordintpair); // Paper - if change, copy into !isChunkLightStatus above
+ // this.d.c(chunkcoordintpair); // Paper - move into post task below
}, () -> {
return "lightChunk " + chunkcoordintpair + " " + flag;
- }));
- return CompletableFuture.supplyAsync(() -> {
+ // Paper start - merge the 2 together
+ }), () -> {
+ this.d.c(chunkcoordintpair); // Paper - release light tickets as post task to ensure they stay loaded until fully done
+ if (skippedPre[0]) return; // Paper - future's already complete
ichunkaccess.b(true);
super.b(chunkcoordintpair, false);
@ -1338,7 +1329,7 @@ index ff00830b95a17f66d0c913087492dbf4b066df8a..4085426af03f032cf405bdfd1e40a8e5
private static final int nibbleBucketSizeMultiplier = Integer.getInteger("Paper.nibbleBucketSize", 3072);
private static final int maxPoolSize = Integer.getInteger("Paper.maxNibblePoolSize", (int) Math.min(6, Math.max(1, Runtime.getRuntime().maxMemory() / 1024 / 1024 / 1024)) * (nibbleBucketSizeMultiplier * 8));
diff --git a/src/main/java/net/minecraft/server/PlayerChunk.java b/src/main/java/net/minecraft/server/PlayerChunk.java
index 27c4dc6caf7b6303766dd8eee4812209600cd728..676f0d28b0c8a590c6429a93902953636b3c1f11 100644
index 1f14ebf09de9f2671b30498ea8fd66750ae85dff..de1e409dc5161371c6f14d036603be448fcd3e26 100644
--- a/src/main/java/net/minecraft/server/PlayerChunk.java
+++ b/src/main/java/net/minecraft/server/PlayerChunk.java
@@ -724,6 +724,7 @@ public class PlayerChunk {