From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Wed, 8 Apr 2020 21:24:05 -0400
Subject: [PATCH] Increase Light Queue Size

Wiz mentioned that large WorldEdit operations cause light to run on
main thread. The queue was small, set to 5.. this bumps it to 20
but makes it configurable per-world.

The main risk of increasing this higher is during shutdown, some
queued light updates may be lost because mojang did not flush the
light engine on shutdown...

The queue size only puts a cap on max loss, doesn't solve that problem.

diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index bf704993d0abd50dba91682a7fbb575e3696be62..a91a7d8f56a068b18d50a8b987b71510b0a19d5b 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -479,5 +479,10 @@ public class PaperWorldConfig {
         disableHopperMoveEvents = getBoolean("hopper.disable-move-event", disableHopperMoveEvents);
         log("Hopper Move Item Events: " + (disableHopperMoveEvents ? "disabled" : "enabled"));
     }
+
+    public int lightQueueSize = 20;
+    private void lightQueueSize() {
+        lightQueueSize = getInt("light-queue-size", lightQueueSize);
+    }
 }
 
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index cc764bb6d7460fd7fc649dd0b7ec61329866dc70..ce5cb696dfa2ff9a07ab9e7547ba54920e58f53a 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -843,7 +843,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
         this.executeModerately();
         // CraftBukkit end
         if (worldserver.getWorld().getKeepSpawnInMemory()) worldloadlistener.stop(); // Paper
-        chunkproviderserver.getLightEngine().setTaskPerBatch(5);
+        chunkproviderserver.getLightEngine().setTaskPerBatch(worldserver.paperConfig.lightQueueSize); // Paper - increase light queue size
         // CraftBukkit start
         // this.updateSpawnFlags();
         worldserver.setSpawnSettings(this.isSpawningMonsters(), this.isSpawningAnimals());
