aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0280-Async-command-map-building.patch
diff options
context:
space:
mode:
authorNoah van der Aa <[email protected]>2024-04-29 23:02:22 +0200
committerNoah van der Aa <[email protected]>2024-04-29 23:02:22 +0200
commit5a954bea77bbe687843615a4017c71d3156b305f (patch)
tree5dd962fc6704a25e37e002550c19f176f049298e /patches/server/0280-Async-command-map-building.patch
parentfbe3c006751aff00e2940a1e9b99bbf15c2f2a37 (diff)
downloadPaper-5a954bea77bbe687843615a4017c71d3156b305f.tar.gz
Paper-5a954bea77bbe687843615a4017c71d3156b305f.zip
1.20.6
Diffstat (limited to 'patches/server/0280-Async-command-map-building.patch')
-rw-r--r--patches/server/0280-Async-command-map-building.patch66
1 files changed, 66 insertions, 0 deletions
diff --git a/patches/server/0280-Async-command-map-building.patch b/patches/server/0280-Async-command-map-building.patch
new file mode 100644
index 0000000000..7f58d78b88
--- /dev/null
+++ b/patches/server/0280-Async-command-map-building.patch
@@ -0,0 +1,66 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Callahan <[email protected]>
+Date: Wed, 8 Apr 2020 02:42:14 -0500
+Subject: [PATCH] Async command map building
+
+This adds a custom pool inorder to make sure that they are closed
+without much though, as it doesn't matter if the client is not sent
+commands if the server is restarting. Using the default async pool caused issues to arise
+due to the shutdown logic generally being much later.
+
+diff --git a/src/main/java/net/minecraft/commands/Commands.java b/src/main/java/net/minecraft/commands/Commands.java
+index eec5279ac4386132fa053c57889e32e6b8141614..b754c0b3e2cd878fca5f702daca64f837ec83451 100644
+--- a/src/main/java/net/minecraft/commands/Commands.java
++++ b/src/main/java/net/minecraft/commands/Commands.java
+@@ -452,6 +452,24 @@ public class Commands {
+ if ( org.spigotmc.SpigotConfig.tabComplete < 0 ) return; // Spigot
+ // CraftBukkit start
+ // Register Vanilla commands into builtRoot as before
++ // Paper start - Perf: Async command map building
++ COMMAND_SENDING_POOL.execute(() -> {
++ this.sendAsync(player);
++ });
++ }
++
++ public static final java.util.concurrent.ThreadPoolExecutor COMMAND_SENDING_POOL = new java.util.concurrent.ThreadPoolExecutor(
++ 0, 2, 60L, java.util.concurrent.TimeUnit.SECONDS,
++ new java.util.concurrent.LinkedBlockingQueue<>(),
++ new com.google.common.util.concurrent.ThreadFactoryBuilder()
++ .setNameFormat("Paper Async Command Builder Thread Pool - %1$d")
++ .setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER))
++ .build(),
++ new java.util.concurrent.ThreadPoolExecutor.DiscardPolicy()
++ );
++
++ private void sendAsync(ServerPlayer player) {
++ // Paper end - Perf: Async command map building
+ Map<CommandNode<CommandSourceStack>, CommandNode<SharedSuggestionProvider>> map = Maps.newIdentityHashMap(); // Use identity to prevent aliasing issues
+ RootCommandNode vanillaRoot = new RootCommandNode();
+
+@@ -469,7 +487,14 @@ public class Commands {
+ for (CommandNode node : rootcommandnode.getChildren()) {
+ bukkit.add(node.getName());
+ }
++ // Paper start - Perf: Async command map building
++ net.minecraft.server.MinecraftServer.getServer().execute(() -> {
++ runSync(player, bukkit, rootcommandnode);
++ });
++ }
+
++ private void runSync(ServerPlayer player, Collection<String> bukkit, RootCommandNode<SharedSuggestionProvider> rootcommandnode) {
++ // Paper end - Perf: Async command map building
+ PlayerCommandSendEvent event = new PlayerCommandSendEvent(player.getBukkitEntity(), new LinkedHashSet<>(bukkit));
+ event.getPlayer().getServer().getPluginManager().callEvent(event);
+
+diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
+index 65e9ac5ba7237e97e286953568f28db86d244d1e..4f4e662e8f21e92b49c3d3811a24f9acedde9fff 100644
+--- a/src/main/java/net/minecraft/server/MinecraftServer.java
++++ b/src/main/java/net/minecraft/server/MinecraftServer.java
+@@ -927,6 +927,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
+ }
+
+ MinecraftServer.LOGGER.info("Stopping server");
++ Commands.COMMAND_SENDING_POOL.shutdownNow(); // Paper - Perf: Async command map building; Shutdown and don't bother finishing
+ MinecraftTimings.stopServer(); // Paper
+ // CraftBukkit start
+ if (this.server != null) {