Restructure lighting queue runnable handling

Instead of overriding add within the queue, never add runnables to the
queue if the light queue is disabled.

This change is made to make timings reports and stacktraces less
confusing for administrators, who prior to this change, would have seen
the lighting queue referenced in both, regardless of whether or not it
was enabled.

This change should not affect performance, nor is it made with the
intent to.
This commit is contained in:
Zach Brown
2017-12-22 15:25:01 -06:00
parent c3791a5225
commit 9ba62bc998
12 changed files with 64 additions and 57 deletions

View File

@@ -6,7 +6,7 @@ Subject: [PATCH] Lighting Queue
This provides option to queue lighting updates to ensure they do not cause the server lag
diff --git a/src/main/java/co/aikar/timings/WorldTimingsHandler.java b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
index e0ad559b7..4eebd9fae 100644
index e0ad559b..4eebd9fa 100644
--- a/src/main/java/co/aikar/timings/WorldTimingsHandler.java
+++ b/src/main/java/co/aikar/timings/WorldTimingsHandler.java
@@ -0,0 +0,0 @@ public class WorldTimingsHandler {
@@ -27,7 +27,7 @@ index e0ad559b7..4eebd9fae 100644
}
}
diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index e524a464f..fd606ee14 100644
index e524a464..fd606ee1 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -0,0 +0,0 @@ public class PaperWorldConfig {
@@ -42,7 +42,7 @@ index e524a464f..fd606ee14 100644
+ }
}
diff --git a/src/main/java/net/minecraft/server/Chunk.java b/src/main/java/net/minecraft/server/Chunk.java
index a4b7d0176..6def9debe 100644
index 66c78083..c1f25e8d 100644
--- a/src/main/java/net/minecraft/server/Chunk.java
+++ b/src/main/java/net/minecraft/server/Chunk.java
@@ -0,0 +0,0 @@ public class Chunk {
@@ -57,7 +57,7 @@ index a4b7d0176..6def9debe 100644
private void h(boolean flag) {
this.world.methodProfiler.a("recheckGaps");
if (this.world.areChunksLoaded(new BlockPosition(this.locX * 16 + 8, 0, this.locZ * 16 + 8), 16)) {
+ lightingQueue.add(() -> recheckGaps(flag)); // Paper - Queue light update
+ this.runOrQueueLightUpdate(() -> recheckGaps(flag)); // Paper - Queue light update
+ }
+ }
+
@@ -68,11 +68,10 @@ index a4b7d0176..6def9debe 100644
for (int j = 0; j < 16; ++j) {
if (this.i[i + j * 16]) {
@@ -0,0 +0,0 @@ public class Chunk {
} else {
if (flag) {
this.initLighting();
- } else {
+ } else { lightingQueue.add(() -> { // Paper - Queue light update
} else {
+ this.runOrQueueLightUpdate(() -> { // Paper - Queue light update
int j1 = iblockdata.c();
int k1 = iblockdata1.c();
@@ -84,8 +83,25 @@ index a4b7d0176..6def9debe 100644
}
TileEntity tileentity;
@@ -0,0 +0,0 @@ public class Chunk {
this.w = i;
}
+ // Paper start
+ public void runOrQueueLightUpdate(Runnable runnable) {
+ if (this.world.paperConfig.queueLightUpdates) {
+ lightingQueue.add(runnable);
+ } else {
+ runnable.run();
+ }
+ }
+ // Paper end
+
public static enum EnumTileEntityState {
IMMEDIATE, QUEUED, CHECK;
diff --git a/src/main/java/net/minecraft/server/ChunkProviderServer.java b/src/main/java/net/minecraft/server/ChunkProviderServer.java
index 024ea5912..ae527d527 100644
index 69ded6aa..e9bc23a6 100644
--- a/src/main/java/net/minecraft/server/ChunkProviderServer.java
+++ b/src/main/java/net/minecraft/server/ChunkProviderServer.java
@@ -0,0 +0,0 @@ public class ChunkProviderServer implements IChunkProvider {
@@ -97,7 +113,7 @@ index 024ea5912..ae527d527 100644
// Update neighbor counts
for (int x = -2; x < 3; x++) {
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index f4d0e2678..5b0431c57 100644
index 47fe9262..d63a243f 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
@@ -119,7 +135,7 @@ index f4d0e2678..5b0431c57 100644
}
diff --git a/src/main/java/net/minecraft/server/PaperLightingQueue.java b/src/main/java/net/minecraft/server/PaperLightingQueue.java
new file mode 100644
index 000000000..d8d3e1efd
index 00000000..345cd582
--- /dev/null
+++ b/src/main/java/net/minecraft/server/PaperLightingQueue.java
@@ -0,0 +0,0 @@
@@ -164,15 +180,6 @@ index 000000000..d8d3e1efd
+ this.chunk = chunk;
+ }
+
+ @Override
+ public boolean add(Runnable runnable) {
+ if (chunk.world.paperConfig.queueLightUpdates) {
+ return super.add(runnable);
+ }
+ runnable.run();
+ return true;
+ }
+
+ /**
+ * Processes the lighting queue for this chunk
+ *
@@ -225,7 +232,7 @@ index 000000000..d8d3e1efd
+ }
+}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
index c25e65428..763f21570 100644
index fd5f8102..77ed2d24 100644
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
@@ -0,0 +0,0 @@ public abstract class World implements IBlockAccess {
@@ -233,7 +240,7 @@ index c25e65428..763f21570 100644
if (iblockdata.c() != iblockdata1.c() || iblockdata.d() != iblockdata1.d()) {
this.methodProfiler.a("checkLight");
- this.w(blockposition);
+ chunk.lightingQueue.add(() -> this.w(blockposition)); // Paper - Queue light update
+ chunk.runOrQueueLightUpdate(() -> this.w(blockposition)); // Paper - Queue light update
this.methodProfiler.b();
}