mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
108 lines
8.3 KiB
Diff
108 lines
8.3 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 80a7a85e1a03a1ca406259207e1ae3b909b3284f..aa2d99de3d23d262542bfb1592fe084f94230f85 100644
|
|
--- a/net/minecraft/Util.java
|
|
+++ b/net/minecraft/Util.java
|
|
@@ -97,7 +97,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.DivineConfig.virtualThreadsEnabled && org.bxteam.divinemc.DivineConfig.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 212d2bcfd34f7cb14e18a8af2cd296fc01d371f6..ec76e4f29ba96b31a24a5d195b852342a57e0bdb 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -474,7 +474,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.DivineConfig.virtualThreadsEnabled && org.bxteam.divinemc.DivineConfig.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 5a0c8791495aa522e511918ad0a24d9bbe6b5877..9d6fa3bced0ba5ab3443bdf4ce306598a8e4a31f 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -2710,8 +2710,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.DivineConfig.virtualThreadsEnabled && org.bxteam.divinemc.DivineConfig.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 a3ec8c92dae7735bb0b1ececc9851c829c486a53..02b4275d170cc854a7482f0e963394aee21171dd 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -808,8 +808,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.DivineConfig.virtualThreadsEnabled && org.bxteam.divinemc.DivineConfig.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 45ea5fa0ef57724acce46008c53f7fa216cf78ee..f4a9d49247d2124b03273c38b14ddf9661184749 100644
|
|
--- a/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
|
@@ -55,7 +55,11 @@ public class ServerLoginPacketListenerImpl implements ServerLoginPacketListener,
|
|
// CraftBukkit end
|
|
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.DivineConfig.virtualThreadsEnabled && org.bxteam.divinemc.DivineConfig.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 5d18f6c3173ed257bef15637a53adbff26ee9062..c843e073db2a0046bbd5b64e1a4f4e956ce88a70 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.DivineConfig.virtualThreadsEnabled && org.bxteam.divinemc.DivineConfig.virtualServerTextFilterPool
|
|
+ ? Executors.newVirtualThreadPerTaskExecutor()
|
|
+ : Executors.newFixedThreadPool(size, THREAD_FACTORY);
|
|
+ // DivineMC end - Virtual Threads
|
|
}
|
|
|
|
protected ServerTextFilter(
|