9
0
mirror of https://github.com/Dreeam-qwq/Gale.git synced 2025-12-26 18:19:11 +00:00

Add thread priority environment variables

This commit is contained in:
Martijn Muijsers
2022-12-22 15:56:19 +01:00
parent c52fdc2744
commit d9b5705b27
8 changed files with 90 additions and 50 deletions

View File

@@ -0,0 +1,30 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Martijn Muijsers <martijnmuijsers@live.nl>
Date: Thu, 22 Dec 2022 15:47:39 +0100
Subject: [PATCH] Server thread priority environment variable
License: GPL-3.0 (https://www.gnu.org/licenses/gpl-3.0.html)
Gale - https://galemc.org
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 609d57dd7373531d35295152e543261e3b0fbe09..d3210128894a8e70919972e60c62bf34338e5fa2 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -195,6 +195,8 @@ import co.aikar.timings.MinecraftTimings; // Paper
public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements CommandSource, AutoCloseable {
+ public static final int SERVER_THREAD_PRIORITY = Integer.getInteger("gale.thread.priority.server", 8); // Gale - server thread priority environment variable
+
private static MinecraftServer SERVER; // Paper
public static final Logger LOGGER = LogUtils.getLogger();
public static final String VANILLA_BRAND = "vanilla";
@@ -326,7 +328,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
S s0 = serverFactory.apply(thread); // CraftBukkit - decompile error
atomicreference.set(s0);
- thread.setPriority(Thread.NORM_PRIORITY+2); // Paper - boost priority
+ thread.setPriority(SERVER_THREAD_PRIORITY); // Gale - server thread priority environment variable
thread.start();
return s0;
}

View File

@@ -485,7 +485,7 @@ index 0c4c62674b4c7e8e3921c7eb3ef726759ac75075..31b488a3c1b81b99bf5bda9f90c3cf69
WorldLoader.InitConfig worldloader_c = Main.loadOrCreateConfig(dedicatedserversettings.getProperties(), convertable_conversionsession, flag, resourcepackrepository);
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d197362f3 100644
index d3210128894a8e70919972e60c62bf34338e5fa2..b2f611d8768f293820c52a8ab515471cd9cdfc60 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -40,7 +40,6 @@ import java.util.Optional;
@@ -521,13 +521,15 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
import org.slf4j.Logger;
// CraftBukkit start
@@ -193,9 +199,17 @@ import org.bukkit.event.server.ServerLoadEvent;
@@ -193,11 +199,19 @@ import org.bukkit.event.server.ServerLoadEvent;
import co.aikar.timings.MinecraftTimings; // Paper
-public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTask> implements CommandSource, AutoCloseable {
+public abstract class MinecraftServer extends MinecraftServerBlockableEventLoop implements CommandSource, AutoCloseable { // Gale - base thread pools
public static final int SERVER_THREAD_PRIORITY = Integer.getInteger("gale.thread.priority.server", 8); // Gale - server thread priority environment variable
- private static MinecraftServer SERVER; // Paper
+ // Gale start - base thread pools
+ public static MinecraftServer SERVER; // Paper // Gale - base thread pools - private -> public
@@ -541,7 +543,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
public static final Logger LOGGER = LogUtils.getLogger();
public static final String VANILLA_BRAND = "vanilla";
private static final float AVERAGE_TICK_TIME_SMOOTHING = 0.8F;
@@ -233,6 +247,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -235,6 +249,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
private int port;
private final LayeredRegistryAccess<RegistryLayer> registries;
private Map<ResourceKey<Level>, ServerLevel> levels;
@@ -552,7 +554,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
private PlayerList playerList;
private volatile boolean running;
private volatile boolean isRestarting = false; // Paper - flag to signify we're attempting to restart
@@ -262,10 +280,115 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -264,10 +282,115 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
private long lastOverloadWarning;
protected final Services services;
private long lastServerStatus;
@@ -672,7 +674,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
private final PackRepository packRepository;
private final ServerScoreboard scoreboard;
@Nullable
@@ -294,7 +417,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -296,7 +419,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public java.util.Queue<Runnable> processQueue = new java.util.concurrent.ConcurrentLinkedQueue<Runnable>();
public int autosavePeriod;
public Commands vanillaCommandDispatcher;
@@ -681,7 +683,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
// CraftBukkit end
// Spigot start
public static final int TPS = 20;
@@ -310,9 +433,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -312,9 +435,9 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public volatile boolean abnormalExit = false; // Paper
public boolean isIteratingOverLevels = false; // Paper
@@ -693,7 +695,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
((MinecraftServer) atomicreference.get()).runServer();
}, "Server thread");
@@ -331,9 +454,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -333,9 +456,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return s0;
}
@@ -708,7 +710,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.metricsRecorder = InactiveMetricsRecorder.INSTANCE;
this.profiler = this.metricsRecorder.getProfiler();
this.onMetricsRecordingStopped = (methodprofilerresults) -> {
@@ -347,7 +473,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -349,7 +475,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.levels = Maps.newLinkedHashMap();
this.running = true;
this.tickTimes = new long[100];
@@ -717,7 +719,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.scoreboard = new ServerScoreboard(this);
this.customBossEvents = new CustomBossEvents();
this.frameTimer = new FrameTimer();
@@ -373,7 +499,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -375,7 +501,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
HolderGetter<Block> holdergetter = this.registries.compositeAccess().registryOrThrow(Registries.BLOCK).asLookup().filterFeatures(this.worldData.enabledFeatures());
this.structureTemplateManager = new StructureTemplateManager(worldstem.resourceManager(), convertable_conversionsession, datafixer, holdergetter);
@@ -729,7 +731,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.executor = Util.backgroundExecutor();
}
// CraftBukkit start
@@ -613,7 +742,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -615,7 +744,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
}
this.forceDifficulty();
@@ -738,7 +740,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.prepareLevels(worldserver.getChunkSource().chunkMap.progressListener, worldserver);
//worldserver.entityManager.tick(); // SPIGOT-6526: Load pending entities so they are available to the API // Paper - rewrite chunk system, not required to "tick" anything
this.server.getPluginManager().callEvent(new org.bukkit.event.world.WorldLoadEvent(worldserver.getWorld()));
@@ -772,7 +901,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -774,7 +903,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
//ChunkProviderServer chunkproviderserver = worldserver.getChunkProvider(); // Paper - move up
chunkproviderserver.getLightEngine().setTaskPerBatch(500);
@@ -747,7 +749,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
// Paper start - configurable spawn reason
int radiusBlocks = worldserver.paperConfig().spawn.keepSpawnLoadedRange * 16;
int radiusChunks = radiusBlocks / 16 + ((radiusBlocks & 15) != 0 ? 1 : 0);
@@ -816,6 +945,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -818,6 +947,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
worldserver.setSpawnSettings(worldserver.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals()); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
this.forceTicks = false;
@@ -759,7 +761,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
// CraftBukkit end
}
@@ -842,8 +976,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -844,8 +978,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end - rewrite chunk system - add close param
boolean flag3 = false;
@@ -774,7 +776,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
if (!suppressLogs) {
MinecraftServer.LOGGER.info("Saving chunks for level '{}'/{}", worldserver, worldserver.dimension().location());
@@ -867,14 +1005,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -869,14 +1007,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
*/
// CraftBukkit end
if (flush) {
@@ -789,7 +791,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
MinecraftServer.LOGGER.info("ThreadedAnvilChunkStorage: All dimensions are saved");
}
@@ -901,7 +1031,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -903,7 +1033,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit start
@@ -798,7 +800,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
public volatile boolean hasFullyShutdown = false; // Paper
private boolean hasLoggedStop = false; // Paper
private final Object stopLock = new Object();
@@ -930,8 +1060,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -932,8 +1062,10 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
*/
MinecraftServer.LOGGER.info("Stopping main thread (Ignore any thread death message you see! - DO NOT REPORT THREAD DEATH TO PAPER - If you think this is a Gale bug, please report it at https://github.com/GaleMC/Gale/issues )");
// Gale end - branding changes
@@ -811,7 +813,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
try {
Thread.sleep(1);
} catch (InterruptedException e) {}
@@ -965,12 +1097,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -967,12 +1099,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
MinecraftServer.LOGGER.info("Saving worlds");
@@ -825,7 +827,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
if (worldserver != null) {
worldserver.noSave = false;
}
@@ -987,9 +1114,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -989,9 +1116,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftServer.LOGGER.error("Failed to unlock level {}", this.storageSource.getLevelId(), ioexception1);
}
// Spigot start
@@ -835,7 +837,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
MinecraftServer.LOGGER.info("Saving usercache.json");
this.getProfileCache().save(false); // Paper
@@ -999,6 +1123,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1001,6 +1125,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
LOGGER.info("Flushing Chunk IO");
io.papermc.paper.chunk.system.io.RegionFileIOThread.close(true); // Paper // Paper - rewrite chunk system
LOGGER.info("Closing Thread Pool");
@@ -849,7 +851,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
Util.shutdownExecutors(); // Paper
LOGGER.info("Closing Server");
try {
@@ -1034,7 +1165,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1036,7 +1167,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
this.running = false;
if (waitForShutdown) {
try {
@@ -858,7 +860,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
} catch (InterruptedException interruptedexception) {
MinecraftServer.LOGGER.error("Error while shutting down", interruptedexception);
}
@@ -1108,6 +1239,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1110,6 +1241,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
public static long lastTickOversleepTime;
// Gale end - YAPFA - last tick time
@@ -866,7 +868,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
protected void runServer() {
try {
long serverStartTime = Util.getNanos(); // Paper
@@ -1115,7 +1247,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1117,7 +1249,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
throw new IllegalStateException("Failed to initialize server");
}
@@ -875,7 +877,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.status.setDescription(Component.literal(this.motd));
this.status.setVersion(new ServerStatus.Version(SharedConstants.getCurrentVersion().getName(), SharedConstants.getCurrentVersion().getProtocolVersion()));
this.status.setEnforcesSecureChat(this.enforceSecureProfile());
@@ -1152,7 +1284,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1154,7 +1286,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (this.server.getWarnOnOverload()) // CraftBukkit
MinecraftServer.LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", i, j);
@@ -884,7 +886,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.lastOverloadWarning = this.nextTickTime;
}
@@ -1181,15 +1313,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1183,15 +1315,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
//MinecraftServer.currentTick = (int) (System.currentTimeMillis() / 50); // CraftBukkit // Paper - don't overwrite current tick time
lastTick = curTime;
@@ -902,7 +904,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.waitUntilNextTick();
this.profiler.pop();
this.endMetricsRecordingTick();
@@ -1272,7 +1403,47 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1274,7 +1405,47 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return crashreport;
}
@@ -951,7 +953,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
// Paper start
if (this.forceTicks) {
return true;
@@ -1280,13 +1451,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1282,13 +1453,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end
// CraftBukkit start
if (isOversleep) return canOversleep();// Paper - because of our changes, this logic is broken
@@ -968,7 +970,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
private boolean canSleepForTickNoOversleep() {
@@ -1295,7 +1466,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1297,7 +1468,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper end
private void executeModerately() {
@@ -977,7 +979,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
java.util.concurrent.locks.LockSupport.parkNanos("executing tasks", 1000L);
}
// CraftBukkit end
@@ -1303,62 +1474,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1305,62 +1476,20 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
protected void waitUntilNextTick() {
//this.executeAll(); // Paper - move this into the tick method for timings
long tickOversleepStart = System.nanoTime(); // Gale - YAPFA - last tick time
@@ -1048,7 +1050,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
private void updateStatusIcon(ServerStatus metadata) {
Optional<File> optional = Optional.of(this.getFile("server-icon.png")).filter(File::isFile);
@@ -1406,14 +1535,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1408,14 +1537,19 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// Paper start - move oversleep into full server tick
isOversleep = true;MinecraftTimings.serverOversleep.startTiming();
@@ -1068,7 +1070,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
this.tickChildren(shouldKeepTicking);
if (i - this.lastServerStatus >= 5000000000L) {
this.lastServerStatus = i;
@@ -1449,7 +1583,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1451,7 +1585,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
if (playerSaveInterval > 0) {
this.playerList.saveAll(playerSaveInterval);
}
@@ -1077,7 +1079,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
if (level.paperConfig().chunks.autoSaveInterval.value() > 0) {
level.saveIncrementally(fullSave);
}
@@ -1462,7 +1596,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1464,7 +1598,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
io.papermc.paper.util.CachedLists.reset(); // Paper
// Paper start - move executeAll() into full server tick timing
try (co.aikar.timings.Timing ignored = MinecraftTimings.processTasksTimer.startTiming()) {
@@ -1086,7 +1088,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
// Paper end
// Paper start
@@ -1510,7 +1644,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1512,7 +1646,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftTimings.timeUpdateTimer.startTiming(); // Spigot // Paper
// Send time updates to everyone, it will get the right time from the world the player is in.
// Paper start - optimize time updates
@@ -1095,7 +1097,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
final boolean doDaylight = world.getGameRules().getBoolean(GameRules.RULE_DAYLIGHT);
final long dayTime = world.getDayTime();
long worldTime = world.getGameTime();
@@ -1530,9 +1664,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1532,9 +1666,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
MinecraftTimings.timeUpdateTimer.stopTiming(); // Spigot // Paper
this.isIteratingOverLevels = true; // Paper
@@ -1106,7 +1108,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
worldserver.hasPhysicsEvent = org.bukkit.event.block.BlockPhysicsEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
worldserver.hasEntityMoveEvent = io.papermc.paper.event.entity.EntityMoveEvent.getHandlerList().getRegisteredListeners().length > 0; // Paper
net.minecraft.world.level.block.entity.HopperBlockEntity.skipHopperEvents = worldserver.paperConfig().hopper.disableMoveEvent || org.bukkit.event.inventory.InventoryMoveItemEvent.getHandlerList().getRegisteredListeners().length == 0; // Paper
@@ -1616,7 +1748,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1618,7 +1750,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public boolean isShutdown() {
@@ -1115,7 +1117,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
public File getFile(String path) {
@@ -1624,7 +1756,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1626,7 +1758,12 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
public final ServerLevel overworld() {
@@ -1129,7 +1131,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
@Nullable
@@ -1638,6 +1775,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1640,6 +1777,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
newLevels.put(level.dimension(), level);
this.levels = Collections.unmodifiableMap(newLevels);
@@ -1143,7 +1145,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
public void removeLevel(ServerLevel level) {
@@ -1645,6 +1789,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1647,6 +1791,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
Map<ResourceKey<Level>, ServerLevel> newLevels = Maps.newLinkedHashMap(oldLevels);
newLevels.remove(level.dimension());
this.levels = Collections.unmodifiableMap(newLevels);
@@ -1158,7 +1160,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
// CraftBukkit end
@@ -1652,8 +1804,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1654,8 +1806,14 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return this.levels.keySet();
}
@@ -1174,7 +1176,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
}
public String getServerVersion() {
@@ -1773,10 +1931,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1775,10 +1933,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
private void updateMobSpawningFlags() {
@@ -1186,7 +1188,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
worldserver.setSpawnSettings(worldserver.serverLevelData.getDifficulty() != Difficulty.PEACEFUL && ((DedicatedServer) this).settings.getProperties().spawnMonsters, this.isSpawningAnimals()); // Paper - per level difficulty (from setDifficulty(ServerLevel, Difficulty, boolean))
}
@@ -1975,25 +2130,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -1977,25 +2132,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
return 29999984;
}
@@ -1212,7 +1214,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
public int getCompressionThreshold() {
return 256;
}
@@ -2060,7 +2196,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2062,7 +2198,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
net.minecraft.world.item.alchemy.PotionBrewing.reload(); // Paper
new io.papermc.paper.event.server.ServerResourcesReloadedEvent(cause).callEvent(); // Paper
// Paper start
@@ -1221,7 +1223,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
return;
}
// this.getPlayerList().saveAll(); // Paper - we don't need to save everything, just advancements
@@ -2302,7 +2438,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2304,7 +2440,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
BufferedWriter bufferedwriter = Files.newBufferedWriter(path);
try {
@@ -1230,7 +1232,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
bufferedwriter.write(String.format(Locale.ROOT, "average_tick_time: %f\n", this.getAverageTickTime()));
bufferedwriter.write(String.format(Locale.ROOT, "tick_times: %s\n", Arrays.toString(this.tickTimes)));
bufferedwriter.write(String.format(Locale.ROOT, "queue: %s\n", Util.backgroundExecutor()));
@@ -2488,7 +2624,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2490,7 +2626,6 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
}
// CraftBukkit start
@@ -1238,7 +1240,7 @@ index 609d57dd7373531d35295152e543261e3b0fbe09..ea3516cbc28fac0620bcb71d3872c50d
public boolean isSameThread() {
return io.papermc.paper.util.TickThread.isTickThread(); // Paper - rewrite chunk system
}
@@ -2742,7 +2877,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@@ -2744,7 +2879,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
// give all worlds a fair chance at by targetting them all.
// if we execute too many tasks, that's fine - we have logic to correctly handle overuse of allocated time.
boolean executed = false;
@@ -5234,10 +5236,10 @@ index 0000000000000000000000000000000000000000..0c625b09df52e3dcd61773af53ccfaf3
+}
diff --git a/src/main/java/org/galemc/gale/executor/thread/pooled/AsyncThreadPool.java b/src/main/java/org/galemc/gale/executor/thread/pooled/AsyncThreadPool.java
new file mode 100644
index 0000000000000000000000000000000000000000..86631b4a33f15f28a64b2559f18283baaefbf9c2
index 0000000000000000000000000000000000000000..e222b367053da90323ded78b2939a7bd2af1da2a
--- /dev/null
+++ b/src/main/java/org/galemc/gale/executor/thread/pooled/AsyncThreadPool.java
@@ -0,0 +1,60 @@
@@ -0,0 +1,64 @@
+// Gale - base thread pools
+
+package org.galemc.gale.executor.thread.pooled;
@@ -5263,6 +5265,8 @@ index 0000000000000000000000000000000000000000..86631b4a33f15f28a64b2559f18283ba
+
+ public static final String targetParallelismEnvironmentVariable = "gale.threads.async";
+
+ public static final int ASYNC_THREAD_PRIORITY = Integer.getInteger("gale.thread.priority.async", 6);
+
+ public static final int MAXIMUM_YIELD_DEPTH = Integer.getInteger("gale.maxyielddepth.async", 100);
+
+ /**
@@ -5286,7 +5290,9 @@ index 0000000000000000000000000000000000000000..86631b4a33f15f28a64b2559f18283ba
+
+ @Override
+ public AsyncThread createThread(int index) {
+ return new AsyncThread(this, index);
+ AsyncThread thread = new AsyncThread(this, index);
+ thread.setPriority(ASYNC_THREAD_PRIORITY);
+ return thread;
+ }
+
+ @Override
@@ -6128,10 +6134,10 @@ index 0000000000000000000000000000000000000000..45c5f483d33e1b5aeb431601dd51d3ec
+}
diff --git a/src/main/java/org/galemc/gale/executor/thread/pooled/TickAssistThreadPool.java b/src/main/java/org/galemc/gale/executor/thread/pooled/TickAssistThreadPool.java
new file mode 100644
index 0000000000000000000000000000000000000000..7f8b0db99e5e49e57d5f043d5adbe68945ce7111
index 0000000000000000000000000000000000000000..51a94ffbd039260bdb84ee80131ae18280ce6064
--- /dev/null
+++ b/src/main/java/org/galemc/gale/executor/thread/pooled/TickAssistThreadPool.java
@@ -0,0 +1,112 @@
@@ -0,0 +1,116 @@
+// Gale - base thread pools
+
+package org.galemc.gale.executor.thread.pooled;
@@ -6158,6 +6164,8 @@ index 0000000000000000000000000000000000000000..7f8b0db99e5e49e57d5f043d5adbe689
+
+ public static final String targetParallelismEnvironmentVariable = "gale.threads.tickassist";
+
+ public static final int TICK_ASSIST_THREAD_PRIORITY = Integer.getInteger("gale.thread.priority.tickassist", 7);
+
+ public static final int MAXIMUM_YIELD_DEPTH = Integer.getInteger("gale.maxyielddepth.tickassist", 100);
+
+ /**
@@ -6202,7 +6210,9 @@ index 0000000000000000000000000000000000000000..7f8b0db99e5e49e57d5f043d5adbe689
+
+ @Override
+ public TickAssistThread createThread(int index) {
+ return new TickAssistThread(this, index);
+ TickAssistThread thread = new TickAssistThread(this, index);
+ thread.setPriority(TICK_ASSIST_THREAD_PRIORITY);
+ return thread;
+ }
+
+ @Override