9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-21 15:59:23 +00:00
Files
DivineMC/divinemc-server/minecraft-patches/features/0024-Virtual-Threads.patch
2025-07-02 19:31:40 +03:00

108 lines
8.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com>
Date: Mon, 24 Feb 2025 19:29:58 +0300
Subject: [PATCH] Virtual Threads
diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java
index 138a58c5e5698b926b01e0170733dc3dbc5589ec..bfe52d5a93a35cafcb8965482b1c1d6c398255e4 100644
--- a/net/minecraft/Util.java
+++ b/net/minecraft/Util.java
@@ -98,7 +98,12 @@ public class Util {
public static final TracingExecutor DIMENSION_DATA_IO_POOL = makeExtraIoExecutor("Dimension-Data-IO-Worker-"); // Paper - Separate dimension data IO pool
private static final TracingExecutor DOWNLOAD_POOL = makeIoExecutor("Download-", true);
// Paper start - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
- public static final ExecutorService PROFILE_EXECUTOR = Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() {
+ // DivineMC start - Virtual Threads
+ public static final ExecutorService PROFILE_EXECUTOR = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualProfileLookupPool
+ ? Executors.newVirtualThreadPerTaskExecutor()
+ : Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory()
+ {
+ // DivineMC end - Virtual Threads
private final AtomicInteger count = new AtomicInteger();
diff --git a/net/minecraft/commands/Commands.java b/net/minecraft/commands/Commands.java
index 25aeb8628a79b62b70dbbb1299d4b4e52986b96d..62aeee570d10ab4ac5c21c88987ba6d2c75ae2b8 100644
--- a/net/minecraft/commands/Commands.java
+++ b/net/minecraft/commands/Commands.java
@@ -475,7 +475,7 @@ public class Commands {
}
// Fixed pool, but with discard policy
- public static final java.util.concurrent.ExecutorService COMMAND_SENDING_POOL = new java.util.concurrent.ThreadPoolExecutor(
+ public static final java.util.concurrent.ExecutorService COMMAND_SENDING_POOL = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualCommandBuilderScheduler ? java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor() : new java.util.concurrent.ThreadPoolExecutor( // DivineMC - Virtual Threads
2, 2, 0, java.util.concurrent.TimeUnit.MILLISECONDS,
new java.util.concurrent.LinkedBlockingQueue<>(),
new com.google.common.util.concurrent.ThreadFactoryBuilder()
diff --git a/net/minecraft/server/MinecraftServer.java b/net/minecraft/server/MinecraftServer.java
index 77a693f42d90b5d17bf56d86b1676247c1ad505d..5c05a41e6f64f37fc365cde6333ed5a684f167f2 100644
--- a/net/minecraft/server/MinecraftServer.java
+++ b/net/minecraft/server/MinecraftServer.java
@@ -2638,8 +2638,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
- public final java.util.concurrent.ExecutorService chatExecutor = java.util.concurrent.Executors.newCachedThreadPool(
- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
+ // DivineMC start - Virtual Threads
+ public final java.util.concurrent.ExecutorService chatExecutor = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualChatScheduler
+ ? java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor()
+ : java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
+ // DivineMC end - Virtual Threads
public final ChatDecorator improvedChatDecorator = new io.papermc.paper.adventure.ImprovedChatDecorator(this); // Paper - adventure
public ChatDecorator getChatDecorator() {
diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index e0a155e057b0683024448c2918c281b049595374..454615d55e50113f871e819b36d62fde0c445e73 100644
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -830,8 +830,11 @@ public class ServerGamePacketListenerImpl
}
// Paper start - AsyncTabCompleteEvent
- private static final java.util.concurrent.ExecutorService TAB_COMPLETE_EXECUTOR = java.util.concurrent.Executors.newFixedThreadPool(4,
- new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Tab Complete Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(MinecraftServer.LOGGER)).build());
+ // DivineMC start - Virtual Threads
+ private static final java.util.concurrent.ExecutorService TAB_COMPLETE_EXECUTOR = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualTabCompleteScheduler
+ ? java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor()
+ : java.util.concurrent.Executors.newFixedThreadPool(4, new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Tab Complete Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(MinecraftServer.LOGGER)).build());
+ // DivineMC end - Virtual Threads
// Paper end - AsyncTabCompleteEvent
@Override
diff --git a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
index 20ba45054c243fbb85e50cf0bdf75648730cb0bc..10aecbb88a9a3dae3ecdf28aa449f1a1475a1905 100644
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
@@ -53,7 +53,11 @@ import org.bukkit.event.player.PlayerPreLoginEvent;
public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener, TickablePacketListener {
private static final AtomicInteger UNIQUE_THREAD_ID = new AtomicInteger(0);
static final Logger LOGGER = LogUtils.getLogger();
- private static final java.util.concurrent.ExecutorService authenticatorPool = java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
+ // DivineMC start - Virtual Threads
+ private static final java.util.concurrent.ExecutorService authenticatorPool = org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualAuthenticatorScheduler
+ ? java.util.concurrent.Executors.newVirtualThreadPerTaskExecutor()
+ : java.util.concurrent.Executors.newCachedThreadPool(new com.google.common.util.concurrent.ThreadFactoryBuilder().setNameFormat("User Authenticator #%d").setUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler(LOGGER)).build()); // Paper - Cache authenticator threads
+ // DivineMC end - Virtual Threads
private static final int MAX_TICKS_BEFORE_LOGIN = 600;
private final byte[] challenge;
final MinecraftServer server;
diff --git a/net/minecraft/server/network/ServerTextFilter.java b/net/minecraft/server/network/ServerTextFilter.java
index b3d46e7687c572d9847124eb58e4a6011a78066c..9d2e2b1cff68383cd19b42e24559e3009ef1df54 100644
--- a/net/minecraft/server/network/ServerTextFilter.java
+++ b/net/minecraft/server/network/ServerTextFilter.java
@@ -48,7 +48,11 @@ public abstract class ServerTextFilter implements AutoCloseable {
final ExecutorService workerPool;
protected static ExecutorService createWorkerPool(int size) {
- return Executors.newFixedThreadPool(size, THREAD_FACTORY);
+ // DivineMC start - Virtual Threads
+ return org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualThreadsEnabled && org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.virtualServerTextFilterPool
+ ? Executors.newVirtualThreadPerTaskExecutor()
+ : Executors.newFixedThreadPool(size, THREAD_FACTORY);
+ // DivineMC end - Virtual Threads
}
protected ServerTextFilter(