mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +00:00
91 lines
6.8 KiB
Diff
91 lines
6.8 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 758ce439d2e10e6ef42a58d147a77093667e0acd..de622982f864d96a5b76efcd69f1836ef541317b 100644
|
|
--- a/net/minecraft/commands/Commands.java
|
|
+++ b/net/minecraft/commands/Commands.java
|
|
@@ -481,7 +481,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 dd88e4d0f72a482e4feea38bc194fc16799adf02..2baa4dc93bcc448ce65bae50ca39d41e562e2211 100644
|
|
--- a/net/minecraft/server/MinecraftServer.java
|
|
+++ b/net/minecraft/server/MinecraftServer.java
|
|
@@ -2640,8 +2640,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 1bd6368704665f90eaa621366b4dec21bc937a96..7b10fe7cf66757ed68f9e39e03259700dfabf184 100644
|
|
--- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -838,8 +838,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/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(
|