From 31ef96b48b65aef4be553765b62022e2b71c7af3 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:17:18 -0700 Subject: Tick the global region scheduler, but not region tasks while sleeping --- ...0835-Folia-scheduler-and-owned-region-API.patch | 47 +++++++++++++++++----- .../server/0918-Add-Lifecycle-Event-system.patch | 4 +- ...boarding-message-for-initial-server-start.patch | 2 +- .../server/0956-Brigadier-based-command-API.patch | 6 +-- patches/server/0983-Optimize-Hoppers.patch | 4 +- patches/server/1021-Tag-Lifecycle-Events.patch | 4 +- .../1038-Moonrise-optimisation-patches.patch | 4 +- .../server/1042-Improved-Watchdog-Support.patch | 4 +- patches/server/1046-Bundle-spark.patch | 9 +++-- .../1048-Incremental-chunk-and-player-saving.patch | 4 +- patches/server/1051-Lag-compensation-ticks.patch | 4 +- ...s-with-certain-tasks-not-processing-durin.patch | 6 +-- 12 files changed, 63 insertions(+), 35 deletions(-) diff --git a/patches/server/0835-Folia-scheduler-and-owned-region-API.patch b/patches/server/0835-Folia-scheduler-and-owned-region-API.patch index 3ff79fb2c6..4be490cc8a 100644 --- a/patches/server/0835-Folia-scheduler-and-owned-region-API.patch +++ b/patches/server/0835-Folia-scheduler-and-owned-region-API.patch @@ -17,10 +17,10 @@ outside of the buffer zone is owned. Then, the plugins may use the schedulers depending on the result of the ownership check. diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java -index d2dee700f2c5cc7d6a272e751a933901fe7a55b6..834b85f24df023642f8abf7213fe578ac8c17a3e 100644 +index d2dee700f2c5cc7d6a272e751a933901fe7a55b6..0cc1545cec32f7208d497c4553eecbd5d1749dbc 100644 --- a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java +++ b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java -@@ -263,6 +263,22 @@ class PaperPluginInstanceManager { +@@ -263,6 +263,30 @@ class PaperPluginInstanceManager { + pluginName + " (Is it up to date?)", ex, plugin); // Paper } @@ -33,6 +33,14 @@ index d2dee700f2c5cc7d6a272e751a933901fe7a55b6..834b85f24df023642f8abf7213fe578a + } + + try { ++ ((io.papermc.paper.threadedregions.scheduler.FallbackRegionScheduler) this.server.getRegionScheduler()) ++ .getBackingScheduler().cancelTasks(plugin); ++ } catch (Throwable ex) { ++ this.handlePluginException("Error occurred (in the plugin loader) while cancelling global tasks for " ++ + pluginName + " (Is it up to date?)", ex, plugin); // Paper ++ } ++ ++ try { + this.server.getAsyncScheduler().cancelTasks(plugin); + } catch (Throwable ex) { + this.handlePluginException("Error occurred (in the plugin loader) while cancelling async tasks for " @@ -232,10 +240,10 @@ index 0000000000000000000000000000000000000000..c03608fec96b51e1867f43d8f42e5aef +} diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/FallbackRegionScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/FallbackRegionScheduler.java new file mode 100644 -index 0000000000000000000000000000000000000000..94056d61a304ee012ae1828a33412516095f996f +index 0000000000000000000000000000000000000000..93b4d55ac10007dde7f97f8d529a40b8a53a0b10 --- /dev/null +++ b/src/main/java/io/papermc/paper/threadedregions/scheduler/FallbackRegionScheduler.java -@@ -0,0 +1,30 @@ +@@ -0,0 +1,40 @@ +package io.papermc.paper.threadedregions.scheduler; + +import org.bukkit.World; @@ -246,24 +254,34 @@ index 0000000000000000000000000000000000000000..94056d61a304ee012ae1828a33412516 + +public final class FallbackRegionScheduler implements RegionScheduler { + ++ private final FoliaGlobalRegionScheduler scheduler; ++ ++ public FallbackRegionScheduler() { ++ this.scheduler = new FoliaGlobalRegionScheduler(); ++ } ++ + @Override + public void execute(@NotNull final Plugin plugin, @NotNull final World world, final int chunkX, final int chunkZ, @NotNull final Runnable run) { -+ plugin.getServer().getGlobalRegionScheduler().execute(plugin, run); ++ this.scheduler.execute(plugin, run); + } + + @Override + public @NotNull ScheduledTask run(@NotNull final Plugin plugin, @NotNull final World world, final int chunkX, final int chunkZ, @NotNull final Consumer task) { -+ return plugin.getServer().getGlobalRegionScheduler().run(plugin, task); ++ return this.scheduler.run(plugin, task); + } + + @Override + public @NotNull ScheduledTask runDelayed(@NotNull final Plugin plugin, @NotNull final World world, final int chunkX, final int chunkZ, @NotNull final Consumer task, final long delayTicks) { -+ return plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, task, delayTicks); ++ return this.scheduler.runDelayed(plugin, task, delayTicks); + } + + @Override + public @NotNull ScheduledTask runAtFixedRate(@NotNull final Plugin plugin, @NotNull final World world, final int chunkX, final int chunkZ, @NotNull final Consumer task, final long initialDelayTicks, final long periodTicks) { -+ return plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, task, initialDelayTicks, periodTicks); ++ return this.scheduler.runAtFixedRate(plugin, task, initialDelayTicks, periodTicks); ++ } ++ ++ public FoliaGlobalRegionScheduler getBackingScheduler() { ++ return this.scheduler; + } +} diff --git a/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java b/src/main/java/io/papermc/paper/threadedregions/scheduler/FoliaAsyncScheduler.java @@ -1148,15 +1166,24 @@ index 0000000000000000000000000000000000000000..d306f911757a4d556c82c0070d4837db + } +} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 8f7a808b0c89953a7f2932e68e2c85f9330469f2..be188079f12b3f7b394ae91db62cc17b1d0f4e79 100644 +index 8f7a808b0c89953a7f2932e68e2c85f9330469f2..9b1d491443600fa3a5f91e36742eef58a03e4ed5 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1625,6 +1625,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { + for (final Entity entity : level.getEntities().getAll()) { + if (entity.isRemoved()) { diff --git a/patches/server/0918-Add-Lifecycle-Event-system.patch b/patches/server/0918-Add-Lifecycle-Event-system.patch index 0eaff54d34..043e06db3e 100644 --- a/patches/server/0918-Add-Lifecycle-Event-system.patch +++ b/patches/server/0918-Add-Lifecycle-Event-system.patch @@ -692,10 +692,10 @@ index 0000000000000000000000000000000000000000..2ed622a61ddc37b11888867770b51390 + } +} diff --git a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java -index 834b85f24df023642f8abf7213fe578ac8c17a3e..3e82ea07ca4194844c5528446e2c4a46ff4acee5 100644 +index 0cc1545cec32f7208d497c4553eecbd5d1749dbc..d6b79638d255f093308512658a88ed85af5042b1 100644 --- a/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java +++ b/src/main/java/io/papermc/paper/plugin/manager/PaperPluginInstanceManager.java -@@ -293,6 +293,15 @@ class PaperPluginInstanceManager { +@@ -301,6 +301,15 @@ class PaperPluginInstanceManager { + pluginName + " (Is it up to date?)", ex, plugin); // Paper } diff --git a/patches/server/0929-Add-onboarding-message-for-initial-server-start.patch b/patches/server/0929-Add-onboarding-message-for-initial-server-start.patch index 73d18bd703..05e905c359 100644 --- a/patches/server/0929-Add-onboarding-message-for-initial-server-start.patch +++ b/patches/server/0929-Add-onboarding-message-for-initial-server-start.patch @@ -29,7 +29,7 @@ index 56798215644d8bca1695856b3a941e8089f49e48..46c37c8db8ecf3cc808fcf59f6bee5fe return instance; } diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index be188079f12b3f7b394ae91db62cc17b1d0f4e79..2de0ae09de41f3ed254318a78d65045fc76e5016 100644 +index 9b1d491443600fa3a5f91e36742eef58a03e4ed5..30321119369794adb613d462d8abe819e5e1b08e 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -1149,6 +1149,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop { @@ -2269,7 +2269,7 @@ index 2de0ae09de41f3ed254318a78d65045fc76e5016..2d2bb7ed1456d90e7d9218a445a1cf26 this.packRepository.setSelected(dataPacks); WorldDataConfiguration worlddataconfiguration = new WorldDataConfiguration(MinecraftServer.getSelectedPacks(this.packRepository, true), this.worldData.enabledFeatures()); -@@ -2232,6 +2234,15 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper - BlockPhysicsEvent worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent diff --git a/patches/server/1021-Tag-Lifecycle-Events.patch b/patches/server/1021-Tag-Lifecycle-Events.patch index 943c370a5b..3701bcdb6a 100644 --- a/patches/server/1021-Tag-Lifecycle-Events.patch +++ b/patches/server/1021-Tag-Lifecycle-Events.patch @@ -474,10 +474,10 @@ index fdc88e52235a152dbe3cca273990b4b68f8daaf8..13797035494a1e010e1da529fb46040f static void loadContentsFromNetwork( diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index e3e3099bb33d21055e480fdbd2df2a3e159f0f1a..843f8ccce6302a6db6cc61c496a5eee21305a88f 100644 +index bfcf74023ab537e0b80570ba61678c91c62ba851..8805eadf9eb1cd9e9c53e4db42c62947f2123bf2 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -2208,7 +2208,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoopmap(resourcepackrepository::getPack).filter(Objects::nonNull).map(Pack::open).collect(ImmutableList.toImmutableList()); // CraftBukkit - decompile error // Paper - decompile error // todo: is this needed anymore? }, this).thenCompose((immutablelist) -> { MultiPackResourceManager resourcemanager = new MultiPackResourceManager(PackType.SERVER_DATA, immutablelist); diff --git a/patches/server/1038-Moonrise-optimisation-patches.patch b/patches/server/1038-Moonrise-optimisation-patches.patch index 68646b52eb..26598c7575 100644 --- a/patches/server/1038-Moonrise-optimisation-patches.patch +++ b/patches/server/1038-Moonrise-optimisation-patches.patch @@ -23386,7 +23386,7 @@ index fc6ce3485dc890f5105a37fe3e344a1460867556..e114e687f2f4503546687fd6792226a6 DedicatedServer dedicatedserver1 = new DedicatedServer(optionset, worldLoader.get(), thread, convertable_conversionsession, resourcepackrepository, worldstem, dedicatedserversettings, DataFixers.getDataFixer(), services, LoggerChunkProgressListener::createFromGameruleRadius); diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index 843f8ccce6302a6db6cc61c496a5eee21305a88f..e0b80b23197307d156ade8427a5227acbc45eb92 100644 +index 8805eadf9eb1cd9e9c53e4db42c62947f2123bf2..45f7adf042befb3eaf7e11e266e8c8b67e8c13b9 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -204,7 +204,7 @@ import org.bukkit.event.server.ServerLoadEvent; @@ -23582,7 +23582,7 @@ index 843f8ccce6302a6db6cc61c496a5eee21305a88f..e0b80b23197307d156ade8427a5227ac return true; } else { boolean ret = false; // Paper - force execution of all worlds, do not just bias the first -@@ -2689,6 +2769,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop= j) { @@ -315,8 +315,9 @@ index 7a671772760152f26e5bb60ea2f2a7765c017c37..8a45960de3fd890991a1c75a103fec1a if (this.emptyTicks == j) { MinecraftServer.LOGGER.info("Server empty for {} seconds, pausing", this.pauseWhileEmptySeconds()); this.autoSave(); - } +@@ -1634,11 +1639,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop S spin(Function serverFactory) { AtomicReference atomicreference = new AtomicReference(); -@@ -1842,6 +1843,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop 0; // Paper - BlockPhysicsEvent worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper - Add EntityMoveEvent net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper - Perf: Optimize Hoppers diff --git a/patches/server/1055-Avoid-issues-with-certain-tasks-not-processing-durin.patch b/patches/server/1055-Avoid-issues-with-certain-tasks-not-processing-durin.patch index ed38a06210..5a9072964b 100644 --- a/patches/server/1055-Avoid-issues-with-certain-tasks-not-processing-durin.patch +++ b/patches/server/1055-Avoid-issues-with-certain-tasks-not-processing-durin.patch @@ -6,12 +6,12 @@ Subject: [PATCH] Avoid issues with certain tasks not processing during sleep Execute processQueue tasks during sleep & unload chunks during sleep diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java -index af7c6f56444c0e495fd39da872f8030199afc634..7933d6900dac67a24fb5f9378097dbde34be30b1 100644 +index 497c58f2050966d59e953fce14c589fd9d1b7a75..af2f2a1b6266390e3f334fa8a0b06cb4d0370ce1 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java -@@ -1639,6 +1639,16 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop