From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Taiyou06 Date: Sun, 6 Apr 2025 11:22:35 +0200 Subject: [PATCH] More virtual threads diff --git a/net/minecraft/Util.java b/net/minecraft/Util.java index 9918572306e983281d05c6d28c8a5d843348ad2d..2491ca5bcabcf8ae99ef990eed4e1fd94f799991 100644 --- a/net/minecraft/Util.java +++ b/net/minecraft/Util.java @@ -98,7 +98,8 @@ 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() { + // Leaf start - More virtual threads + public static final ExecutorService PROFILE_EXECUTOR = createProfileExecutor(); /* new Executors.newFixedThreadPool(2, new java.util.concurrent.ThreadFactory() { private final AtomicInteger count = new AtomicInteger(); @@ -111,7 +112,30 @@ public class Util { }); return ret; } - }); + }); */ + + private static ExecutorService createProfileExecutor() { + final java.util.concurrent.ThreadFactory factory; + if (org.dreeam.leaf.config.modules.opt.VT4ProfileExecutor.enabled && org.galemc.gale.virtualthread.VirtualThreadService.isSupported()) { + factory = org.galemc.gale.virtualthread.VirtualThreadService.get().createFactory(); + } else { + factory = new java.util.concurrent.ThreadFactory() { + private final AtomicInteger count = new AtomicInteger(); + + @Override + public Thread newThread(Runnable run) { + Thread ret = new Thread(run); + ret.setName("Profile Lookup Executor #" + this.count.getAndIncrement()); + ret.setUncaughtExceptionHandler((Thread thread, Throwable throwable) -> { + LOGGER.error("Uncaught exception in thread " + thread.getName(), throwable); + }); + return ret; + } + }; + } + return Executors.newFixedThreadPool(2, factory); + } + // Leaf end - More virtual threads // Paper end - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread private static final DateTimeFormatter FILENAME_DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT); public static final int LINEAR_LOOKUP_THRESHOLD = 8;