From 880ce4bded3c1984cdece675ad96a9f0adc2c294 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sun, 29 Jun 2025 15:37:48 +0300 Subject: [PATCH] remove old shit --- .../0010-Chunk-System-Optimizations.patch | 364 ++++++++++-------- .../features/0012-Lag-compensation.patch | 10 +- .../features/0027-Async-Chunk-Sending.patch | 4 +- .../0037-Dynamic-Activation-of-Brain.patch | 4 +- .../0045-Parallel-world-ticking.patch | 23 +- .../0046-MSPT-Tracking-for-each-world.patch | 4 +- .../features/0047-Optimize-Raids.patch | 6 +- .../0053-Regionized-Chunk-Ticking.patch | 6 +- .../0005-Chunk-System-Optimizations.patch | 49 ++- ...07-Configurable-thread-pool-priority.patch | 4 +- .../structs/DynamicPriorityQueue.java | 9 +- .../bxteam/divinemc/config/DivineConfig.java | 15 - .../divinemc/server/chunk/ChunkRunnable.java | 32 -- .../server/chunk/ChunkSystemAlgorithms.java | 116 ------ .../server/chunk/ChunkSystemTaskQueue.java | 28 +- .../server/chunk/ChunkTaskPriority.java | 6 - .../server/chunk/PriorityHandler.java | 32 -- 17 files changed, 265 insertions(+), 447 deletions(-) delete mode 100644 divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkRunnable.java delete mode 100644 divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemAlgorithms.java delete mode 100644 divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java delete mode 100644 divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/PriorityHandler.java diff --git a/divinemc-server/minecraft-patches/features/0010-Chunk-System-Optimizations.patch b/divinemc-server/minecraft-patches/features/0010-Chunk-System-Optimizations.patch index 34342b8..5680750 100644 --- a/divinemc-server/minecraft-patches/features/0010-Chunk-System-Optimizations.patch +++ b/divinemc-server/minecraft-patches/features/0010-Chunk-System-Optimizations.patch @@ -31,80 +31,176 @@ index 93272808d94e81d31af728ebe85df9a2bc7aedab..17c0f25206b12665518142f27c17d17f } diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -index b2bcfb3557a0326fd7ec1059f95d6da4568dfd80..6bb36686ae7ca9f4bf763baa894086146f967806 100644 +index b2bcfb3557a0326fd7ec1059f95d6da4568dfd80..325f02fa5b4e429f30bd625a74623101ad92d3e2 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java -@@ -405,6 +405,14 @@ public final class ChunkEntitySlices { - - private E[] storage; - private int size; -+ private it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap entityToIndex = null; // DivineMC - Chunk System optimization -+ -+ // DivineMC start - Chunk System optimization -+ private void setupIndexMap() { -+ this.entityToIndex = new it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap(2, 0.8f); -+ this.entityToIndex.defaultReturnValue(Integer.MIN_VALUE); -+ } -+ // DivineMC end - Chunk System optimization - - public BasicEntityList() { - this(0); -@@ -425,6 +433,7 @@ public final class ChunkEntitySlices { - private void resize() { - if (this.storage == EMPTY) { - this.storage = (E[])new Entity[DEFAULT_CAPACITY]; -+ this.setupIndexMap(); // DivineMC - Chunk System optimization - } else { - this.storage = Arrays.copyOf(this.storage, this.storage.length * 2); - } -@@ -438,6 +447,7 @@ public final class ChunkEntitySlices { - } else { - this.storage[idx] = entity; - } -+ this.entityToIndex.put(entity.getId(), idx); // DivineMC - Chunk System optimization - } - - public int indexOf(final E entity) { -@@ -453,24 +463,31 @@ public final class ChunkEntitySlices { - } - - public boolean remove(final E entity) { -- final int idx = this.indexOf(entity); -- if (idx == -1) { -+ // DivineMC start - Chunk System optimization - by Sakura, copied from EntityList -+ if (this.entityToIndex == null) { - return false; - } - -- final int size = --this.size; -- final E[] storage = this.storage; -- if (idx != size) { -- System.arraycopy(storage, idx + 1, storage, idx, size - idx); -+ final int index = this.entityToIndex.remove(entity.getId()); -+ if (index == Integer.MIN_VALUE) { -+ return false; - } - -- storage[size] = null; -+ final int endIndex = --this.size; -+ final E end = this.storage[endIndex]; -+ if (index != endIndex) { -+ // not empty after this call -+ this.entityToIndex.put(end.getId(), index); // update index -+ } -+ this.storage[index] = end; -+ this.storage[endIndex] = null; -+ // DivineMC end - Chunk System optimization - by Sakura, copied from EntityList - - return true; - } - - public boolean has(final E entity) { -- return this.indexOf(entity) != -1; -+ return this.entityToIndex != null && this.entityToIndex.containsKey(entity.getId()); // DivineMC - Chunk System optimization +@@ -225,8 +225,10 @@ public final class ChunkEntitySlices { } } ++ public final java.util.concurrent.locks.ReentrantLock statusLock = new java.util.concurrent.locks.ReentrantLock(); // DivineMC - Chunk System Optimizations + private boolean preventStatusUpdates; + public boolean startPreventingStatusUpdates() { ++ this.statusLock.lock(); // DivineMC - Chunk System Optimizations + final boolean ret = this.preventStatusUpdates; + this.preventStatusUpdates = true; + return ret; +@@ -238,85 +240,104 @@ public final class ChunkEntitySlices { + + public void stopPreventingStatusUpdates(final boolean prev) { + this.preventStatusUpdates = prev; ++ this.statusLock.unlock(); // DivineMC - Chunk System Optimizations + } + + public void updateStatus(final FullChunkStatus status, final EntityLookup lookup) { +- this.status = status; ++ // DivineMC start - Chunk System Optimizations ++ this.statusLock.lock(); try { ++ this.status = status; + +- final Entity[] entities = this.entities.getRawData(); ++ final Entity[] entities = this.entities.getRawData(); + +- for (int i = 0, size = this.entities.size(); i < size; ++i) { +- final Entity entity = entities[i]; ++ for (int i = 0, size = this.entities.size(); i < size; ++i) { ++ final Entity entity = entities[i]; + +- final Visibility oldVisibility = EntityLookup.getEntityStatus(entity); +- ((ChunkSystemEntity)entity).moonrise$setChunkStatus(status); +- final Visibility newVisibility = EntityLookup.getEntityStatus(entity); ++ final Visibility oldVisibility = EntityLookup.getEntityStatus(entity); ++ ((ChunkSystemEntity) entity).moonrise$setChunkStatus(status); ++ final Visibility newVisibility = EntityLookup.getEntityStatus(entity); + +- lookup.entityStatusChange(entity, this, oldVisibility, newVisibility, false, false, false); ++ lookup.entityStatusChange(entity, this, oldVisibility, newVisibility, false, false, false); ++ } ++ } finally { ++ this.statusLock.unlock(); + } ++ // DivineMC end - Chunk System Optimizations + } + + public boolean addEntity(final Entity entity, final int chunkSection) { +- if (!this.entities.add(entity)) { +- return false; +- } +- ((ChunkSystemEntity)entity).moonrise$setChunkStatus(this.status); +- ((ChunkSystemEntity)entity).moonrise$setChunkData(this.chunkData); +- final int sectionIndex = chunkSection - this.minSection; ++ // DivineMC start - Chunk System Optimizations ++ this.statusLock.lock(); try { ++ if (!this.entities.add(entity)) { ++ return false; ++ } ++ ((ChunkSystemEntity) entity).moonrise$setChunkStatus(this.status); ++ ((ChunkSystemEntity) entity).moonrise$setChunkData(this.chunkData); ++ final int sectionIndex = chunkSection - this.minSection; + +- this.allEntities.addEntity(entity, sectionIndex); ++ this.allEntities.addEntity(entity, sectionIndex); + +- if (((ChunkSystemEntity)entity).moonrise$isHardColliding()) { +- this.hardCollidingEntities.addEntity(entity, sectionIndex); +- } ++ if (((ChunkSystemEntity) entity).moonrise$isHardColliding()) { ++ this.hardCollidingEntities.addEntity(entity, sectionIndex); ++ } + +- for (final Iterator, EntityCollectionBySection>> iterator = +- this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) { +- final Reference2ObjectMap.Entry, EntityCollectionBySection> entry = iterator.next(); ++ for (final Iterator, EntityCollectionBySection>> iterator = ++ this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext(); ) { ++ final Reference2ObjectMap.Entry, EntityCollectionBySection> entry = iterator.next(); + +- if (entry.getKey().isInstance(entity)) { +- entry.getValue().addEntity(entity, sectionIndex); ++ if (entry.getKey().isInstance(entity)) { ++ entry.getValue().addEntity(entity, sectionIndex); ++ } + } +- } + +- EntityCollectionBySection byType = this.entitiesByType.get(entity.getType()); +- if (byType != null) { +- byType.addEntity(entity, sectionIndex); +- } else { +- this.entitiesByType.put(entity.getType(), byType = new EntityCollectionBySection(this)); +- byType.addEntity(entity, sectionIndex); +- } ++ EntityCollectionBySection byType = this.entitiesByType.get(entity.getType()); ++ if (byType != null) { ++ byType.addEntity(entity, sectionIndex); ++ } else { ++ this.entitiesByType.put(entity.getType(), byType = new EntityCollectionBySection(this)); ++ byType.addEntity(entity, sectionIndex); ++ } + +- return true; ++ return true; ++ } finally { ++ this.statusLock.unlock(); ++ } ++ // DivineMC end - Chunk System Optimizations + } + + public boolean removeEntity(final Entity entity, final int chunkSection) { +- if (!this.entities.remove(entity)) { +- return false; +- } +- ((ChunkSystemEntity)entity).moonrise$setChunkStatus(null); +- ((ChunkSystemEntity)entity).moonrise$setChunkData(null); +- final int sectionIndex = chunkSection - this.minSection; ++ // DivineMC start - Chunk System Optimizations ++ this.statusLock.lock(); try { ++ if (!this.entities.remove(entity)) { ++ return false; ++ } ++ ((ChunkSystemEntity) entity).moonrise$setChunkStatus(null); ++ ((ChunkSystemEntity) entity).moonrise$setChunkData(null); ++ final int sectionIndex = chunkSection - this.minSection; + +- this.allEntities.removeEntity(entity, sectionIndex); ++ this.allEntities.removeEntity(entity, sectionIndex); + +- if (((ChunkSystemEntity)entity).moonrise$isHardColliding()) { +- this.hardCollidingEntities.removeEntity(entity, sectionIndex); +- } ++ if (((ChunkSystemEntity) entity).moonrise$isHardColliding()) { ++ this.hardCollidingEntities.removeEntity(entity, sectionIndex); ++ } + +- for (final Iterator, EntityCollectionBySection>> iterator = +- this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) { +- final Reference2ObjectMap.Entry, EntityCollectionBySection> entry = iterator.next(); ++ for (final Iterator, EntityCollectionBySection>> iterator = ++ this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext(); ) { ++ final Reference2ObjectMap.Entry, EntityCollectionBySection> entry = iterator.next(); + +- if (entry.getKey().isInstance(entity)) { +- entry.getValue().removeEntity(entity, sectionIndex); ++ if (entry.getKey().isInstance(entity)) { ++ entry.getValue().removeEntity(entity, sectionIndex); ++ } + } +- } + +- final EntityCollectionBySection byType = this.entitiesByType.get(entity.getType()); +- byType.removeEntity(entity, sectionIndex); ++ final EntityCollectionBySection byType = this.entitiesByType.get(entity.getType()); ++ byType.removeEntity(entity, sectionIndex); + +- return true; ++ return true; ++ } finally { ++ this.statusLock.unlock(); ++ } ++ // DivineMC end - Chunk System Optimizations + } + + public void getHardCollidingEntities(final Entity except, final AABB box, final List into, final Predicate predicate) { diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java b/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..950b284cb3b4488a794e6c6f936f55ea427ef7cc 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java @@ -143,7 +239,7 @@ index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..950b284cb3b4488a794e6c6f936f55ea protected boolean addEntity(final Entity entity, final boolean fromDisk, final boolean event) { diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java -index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b40585fc3 100644 +index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..636ba1c5fef58aabd5b8d6c6a8d183584b9c8be1 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java @@ -191,13 +191,13 @@ public final class RegionizedPlayerChunkLoader { @@ -179,31 +275,22 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b private int lastChunkX = Integer.MIN_VALUE; private int lastChunkZ = Integer.MIN_VALUE; -@@ -386,10 +387,19 @@ public final class RegionizedPlayerChunkLoader { +@@ -386,10 +387,12 @@ public final class RegionizedPlayerChunkLoader { final int centerX = PlayerChunkLoaderData.this.lastChunkX; final int centerZ = PlayerChunkLoaderData.this.lastChunkZ; -- return Integer.compare( ++ // DivineMC start - Chunk System Optimization + return Integer.compare( - Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), - Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) -- ); -+ // DivineMC start - Chunk Loading Priority Optimization -+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkTaskPriority == org.bxteam.divinemc.server.chunk.ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN) { -+ return Integer.compare( -+ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ), -+ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ) -+ ); -+ } else { -+ return Integer.compare( -+ Math.abs(c1x - centerX) + Math.abs(c1z - centerZ), -+ Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) -+ ); -+ } -+ // DivineMC end - Chunk Loading Priority Optimization ++ (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ), ++ (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ) + ); ++ // DivineMC end - Chunk System Optimization }; private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); private final LongHeapPriorityQueue tickingQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); -@@ -857,6 +867,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -857,6 +860,7 @@ public final class RegionizedPlayerChunkLoader { } void add() { @@ -211,7 +298,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b TickThread.ensureTickThread(this.player, "Cannot add player asynchronously"); if (this.removed) { throw new IllegalStateException("Adding removed player chunk loader"); -@@ -896,6 +907,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -896,6 +900,7 @@ public final class RegionizedPlayerChunkLoader { // now we can update this.update(); @@ -219,7 +306,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b } private boolean isLoadedChunkGeneratable(final int chunkX, final int chunkZ) { -@@ -1064,6 +1076,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -1064,6 +1069,7 @@ public final class RegionizedPlayerChunkLoader { } void remove() { @@ -227,7 +314,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b TickThread.ensureTickThread(this.player, "Cannot add player asynchronously"); if (this.removed) { throw new IllegalStateException("Removing removed player chunk loader"); -@@ -1091,7 +1104,7 @@ public final class RegionizedPlayerChunkLoader { +@@ -1091,7 +1097,7 @@ public final class RegionizedPlayerChunkLoader { } public LongOpenHashSet getSentChunksRaw() { @@ -237,7 +324,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b } } diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java -index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b25876ee9058 100644 +index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..c10e31017e7dfab348e9cc45c28d3858863ac0b1 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java @@ -73,37 +73,50 @@ public final class ChunkHolderManager { @@ -361,12 +448,9 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258 public void saveAllChunks(final boolean flush, final boolean shutdown, final boolean logProgress) { final List holders = this.getChunkHolders(); -@@ -321,13 +338,9 @@ public final class ChunkHolderManager { - } - if (logProgress) { +@@ -323,11 +340,7 @@ public final class ChunkHolderManager { final long currTime = System.nanoTime(); -- if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(10L)) { -+ if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(5L)) { // DivineMC - Log a bit more frequently + if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(10L)) { lastLog = currTime; - LOGGER.info( - "Saved " + savedChunk + " block chunks, " + savedEntity + " entity chunks, " + savedPoi @@ -430,23 +514,12 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258 if (!this.sectionToChunkToExpireCount.containsKey(sectionKey)) { // removed concurrently -@@ -1145,18 +1158,29 @@ public final class ChunkHolderManager { +@@ -1145,18 +1158,18 @@ public final class ChunkHolderManager { if (!TickThread.isTickThread()) { // These will be handled on the next ServerChunkCache$MainThreadExecutor#pollTask, as it runs the distance manager update // which will invoke processTicketUpdates - this.offThreadPendingFullLoadUpdate.addAll(changedFullStatus); + this.getData().offThreadPendingFullLoadUpdate.addAll(changedFullStatus); // DivineMC - Chunk System optimization -+ -+ // DivineMC start - Chunk System optimization -+ this.taskScheduler.scheduleChunkTask(() -> { -+ final java.util.Deque pendingFullLoadUpdate = ChunkHolderManager.this.getData().pendingFullLoadUpdate; -+ for (int i = 0, len = changedFullStatus.size(); i < len; ++i) { -+ pendingFullLoadUpdate.add(changedFullStatus.get(i)); -+ } -+ -+ ChunkHolderManager.this.processPendingFullUpdate(); -+ }, Priority.HIGHEST); -+ // DivineMC end - Chunk System optimization } else { - final ArrayDeque pendingFullLoadUpdate = this.pendingFullLoadUpdate; + final java.util.Deque pendingFullLoadUpdate = this.getData().pendingFullLoadUpdate; // DivineMC - Chunk System optimization @@ -464,7 +537,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258 PlatformHooks.get().onChunkHolderDelete(this.world, holder.vanillaChunkHolder); this.chunkHolders.remove(CoordinateUtils.getChunkKey(holder.chunkX, holder.chunkZ)); } -@@ -1314,6 +1338,27 @@ public final class ChunkHolderManager { +@@ -1314,6 +1327,27 @@ public final class ChunkHolderManager { } } @@ -492,7 +565,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258 public enum TicketOperationType { ADD, REMOVE, ADD_IF_REMOVED, ADD_AND_REMOVE } -@@ -1473,8 +1518,8 @@ public final class ChunkHolderManager { +@@ -1473,8 +1507,8 @@ public final class ChunkHolderManager { // only call on tick thread private void processOffThreadFullUpdates() { @@ -503,7 +576,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258 NewChunkHolder toUpdate; while ((toUpdate = offThreadPendingFullLoadUpdate.poll()) != null) { -@@ -1486,7 +1531,7 @@ public final class ChunkHolderManager { +@@ -1486,7 +1520,7 @@ public final class ChunkHolderManager { private boolean processPendingFullUpdate() { this.processOffThreadFullUpdates(); @@ -512,7 +585,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258 boolean ret = false; -@@ -1522,8 +1567,7 @@ public final class ChunkHolderManager { +@@ -1522,8 +1556,7 @@ public final class ChunkHolderManager { final JsonArray allTicketsJson = new JsonArray(); ret.add("tickets", allTicketsJson); @@ -581,7 +654,7 @@ index 8f8268924ac92fca5df8a11e08031fa8416c6e05..f1bc7a5e80de0293e1837b2f7401b347 } diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java -index 2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a..772694b751057aca58cea51741ebc45189078117 100644 +index 2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a..cf7ecf226f7090ca598423aed83249a8e3c19fe1 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java @@ -646,11 +646,19 @@ public final class NewChunkHolder { @@ -600,11 +673,11 @@ index 2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a..772694b751057aca58cea51741ebc451 this.world = world; this.chunkX = chunkX; this.chunkZ = chunkZ; -+ this.cachedLongPos = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(this.chunkX, this.chunkZ); // DivineMC - Chunk System optimization ++ this.cachedLongPos = ((long)chunkZ << 32) | (chunkX & 0xFFFFFFFFL); // DivineMC - Chunk System optimization this.scheduler = scheduler; this.vanillaChunkHolder = new ChunkHolder( new ChunkPos(chunkX, chunkZ), ChunkHolderManager.MAX_TICKET_LEVEL, world, -@@ -792,12 +800,14 @@ public final class NewChunkHolder { +@@ -792,9 +800,11 @@ public final class NewChunkHolder { // note: these are completed with null to indicate that no write occurred // they are also completed with null to indicate a null write occurred @@ -618,20 +691,7 @@ index 2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a..772694b751057aca58cea51741ebc451 + // DivineMC end - Chunk System optimization public static final record UnloadTask(CallbackCompletable completable, PrioritisedExecutor.PrioritisedTask task, -- LazyRunnable toRun) {} -+ org.bxteam.divinemc.server.chunk.ChunkRunnable toRun) {} // DivineMC - Chunk System optimization - - public UnloadTask getUnloadTask(final MoonriseRegionFileIO.RegionFileType type) { - switch (type) { -@@ -860,7 +870,7 @@ public final class NewChunkHolder { - this.priorityLocked = false; - - if (chunk != null) { -- final LazyRunnable toRun = new LazyRunnable(); -+ final org.bxteam.divinemc.server.chunk.ChunkRunnable toRun = new org.bxteam.divinemc.server.chunk.ChunkRunnable(this.chunkX, this.chunkZ, this.world, null); // DivineMC - Chunk System optimization' - this.chunkDataUnload = new UnloadTask(new CallbackCompletable<>(), this.scheduler.saveExecutor.createTask(toRun), toRun); - } - if (poiChunk != null) { + LazyRunnable toRun) {} @@ -879,7 +889,11 @@ public final class NewChunkHolder { MoonriseRegionFileIO.scheduleSave(this.world, this.chunkX, this.chunkZ, data, type); } @@ -673,34 +733,24 @@ index 2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a..772694b751057aca58cea51741ebc451 } // only to be called on the main thread, no locks need to be held -@@ -1350,11 +1378,11 @@ public final class NewChunkHolder { +@@ -1350,7 +1378,7 @@ public final class NewChunkHolder { return this.requestedGenStatus; } - private final Reference2ObjectOpenHashMap>> statusWaiters = new Reference2ObjectOpenHashMap<>(); -+ private final Map>> statusWaiters = new java.util.concurrent.ConcurrentHashMap<>(); // DivineMC - Chunk System optimization ++ private final Reference2ObjectMap>> statusWaiters = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>()); // DivineMC - Chunk System optimization void addStatusConsumer(final ChunkStatus status, final Consumer consumer) { this.statusWaiters.computeIfAbsent(status, (final ChunkStatus keyInMap) -> { -- return new ArrayList<>(4); -+ return new java.util.concurrent.CopyOnWriteArrayList<>(); // DivineMC - Chunk System optimization - }).add(consumer); - } - -@@ -1396,11 +1424,11 @@ public final class NewChunkHolder { +@@ -1396,7 +1424,7 @@ public final class NewChunkHolder { }, Priority.HIGHEST); } - private final Reference2ObjectOpenHashMap>> fullStatusWaiters = new Reference2ObjectOpenHashMap<>(); -+ private final Map>> fullStatusWaiters = new java.util.concurrent.ConcurrentHashMap<>(); // DivineMC - Chunk System optimization ++ private final Reference2ObjectMap>> fullStatusWaiters = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>()); // DivineMC - Chunk System optimization void addFullStatusConsumer(final FullChunkStatus status, final Consumer consumer) { this.fullStatusWaiters.computeIfAbsent(status, (final FullChunkStatus keyInMap) -> { -- return new ArrayList<>(4); -+ return new java.util.concurrent.CopyOnWriteArrayList<>(); // DivineMC - Chunk System optimization - }).add(consumer); - } - diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/executor/RadiusAwarePrioritisedExecutor.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/executor/RadiusAwarePrioritisedExecutor.java index 28ffa653e87a4e8ef7cf614916ef3fe61681fe16..b35b92b204fbefd139c4544f15e32d46bfa30777 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/executor/RadiusAwarePrioritisedExecutor.java @@ -1075,7 +1125,7 @@ index 879d6eb8e72b63bc95d8028cbc2f6e93e516ab1d..6de832e7aec630914e70fb0f11223907 } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee6a4e4c4d 100644 +index 740f6324eeb4021bc45d27d6145ff71282c761c2..efda5818ac05cbf06b93a1c983d6e3b18412ca86 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -179,6 +179,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -1086,15 +1136,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee private int lastSpawnChunkRadius; final EntityTickList entityTickList = new EntityTickList(); private final ServerWaypointManager waypointManager; -@@ -290,6 +291,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe - } - // Paper end - optimise getPlayerByUUID - // Paper start - rewrite chunk system -+ public final org.bxteam.divinemc.server.chunk.PriorityHandler chunkSystemPriorities; - private final ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder viewDistanceHolder = new ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader.ViewDistanceHolder(); - private final ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader chunkLoader = new ca.spottedleaf.moonrise.patches.chunk_system.player.RegionizedPlayerChunkLoader((ServerLevel)(Object)this); - private final ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController entityDataController; -@@ -682,6 +684,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -682,6 +683,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // Paper start - rewrite chunk system this.moonrise$setEntityLookup(new ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup((ServerLevel)(Object)this, ((ServerLevel)(Object)this).new EntityCallbacks())); this.chunkTaskScheduler = new ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler((ServerLevel)(Object)this); @@ -1102,15 +1144,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee this.entityDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController( new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController.EntityRegionFileStorage( new RegionStorageInfo(levelStorageAccess.getLevelId(), dimension, "entities"), -@@ -695,6 +698,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe - // Paper end - rewrite chunk system - this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit - this.preciseTime = this.serverLevelData.getDayTime(); // Purpur - Configurable daylight cycle -+ this.chunkSystemPriorities = new org.bxteam.divinemc.server.chunk.PriorityHandler(this); // DivineMC - Chunk System optimizations - } - - // Paper start -@@ -825,8 +829,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -825,8 +827,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @Override public boolean shouldTickBlocksAt(long chunkPos) { // Paper start - rewrite chunk system @@ -1120,7 +1154,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee // Paper end - rewrite chunk system } -@@ -882,7 +885,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -882,7 +883,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe private void optimiseRandomTick(final LevelChunk chunk, final int tickSpeed) { final LevelChunkSection[] sections = chunk.getSections(); @@ -1129,7 +1163,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom; final boolean doubleTickFluids = !ca.spottedleaf.moonrise.common.PlatformHooks.get().configFixMC224294(); -@@ -890,42 +893,41 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -890,42 +891,41 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe final int offsetX = cpos.x << 4; final int offsetZ = cpos.z << 4; @@ -1182,7 +1216,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee } // Paper end - optimise random ticking -@@ -2558,16 +2560,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -2558,16 +2558,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe public boolean isPositionTickingWithEntitiesLoaded(long chunkPos) { // Paper start - rewrite chunk system diff --git a/divinemc-server/minecraft-patches/features/0012-Lag-compensation.patch b/divinemc-server/minecraft-patches/features/0012-Lag-compensation.patch index c61eaff..38d2a80 100644 --- a/divinemc-server/minecraft-patches/features/0012-Lag-compensation.patch +++ b/divinemc-server/minecraft-patches/features/0012-Lag-compensation.patch @@ -25,7 +25,7 @@ index abfecaf4467092f7baa02e0f5bbfd23d087f2aa3..77a693f42d90b5d17bf56d86b1676247 this.tickCount++; this.tickRateManager.tick(); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 14c8df2f3b9c133b38e871e81f7ee2333322437c..05b8834b5566ac12655b563a1a58f123275fdedb 100644 +index efda5818ac05cbf06b93a1c983d6e3b18412ca86..ebd4b7c36e1cece8730782764c476756feebc211 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -216,6 +216,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -36,7 +36,7 @@ index 14c8df2f3b9c133b38e871e81f7ee2333322437c..05b8834b5566ac12655b563a1a58f123 @Override public @Nullable LevelChunk getChunkIfLoaded(int x, int z) { -@@ -766,6 +767,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -764,6 +765,8 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } } @@ -45,7 +45,7 @@ index 14c8df2f3b9c133b38e871e81f7ee2333322437c..05b8834b5566ac12655b563a1a58f123 this.updateSkyBrightness(); if (runsNormally) { this.tickTime(); -@@ -846,11 +849,18 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -844,11 +847,18 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.setDayTime(this.preciseTime); } else // Purpur end - Configurable daylight cycle @@ -66,7 +66,7 @@ index 14c8df2f3b9c133b38e871e81f7ee2333322437c..05b8834b5566ac12655b563a1a58f123 this.serverLevelData.setDayTime(time); // Purpur start - Configurable daylight cycle diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java -index e3babfa292556c5f5a208536a3f869dc71b82498..16a3cd813997456ca67a382a8277eca02dc6662f 100644 +index b8bd792293cb5985db5e5dfa5644930971a34632..a24829b705945fbda1058d9848b829500e727304 100644 --- a/net/minecraft/world/entity/LivingEntity.java +++ b/net/minecraft/world/entity/LivingEntity.java @@ -517,6 +517,7 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin @@ -220,7 +220,7 @@ index 2d9bf302b779602d733187c6f86e52467f0dc540..69196d7e43054955137569b22c4ca40a public static class BooleanValue extends GameRules.Value { private boolean value; diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java -index 36e754dedc9e7b97dc5565864f5664d062ff612a..346d1825a9ed03c61f6915edc2b8d96dd0ead3e4 100644 +index 8db95b74f88f8096de93115ae8d3fb2e6184ad3b..e044830439fe9821ab3f62695d318a6321b8a266 100644 --- a/net/minecraft/world/level/block/state/BlockBehaviour.java +++ b/net/minecraft/world/level/block/state/BlockBehaviour.java @@ -347,13 +347,21 @@ public abstract class BlockBehaviour implements FeatureElement { diff --git a/divinemc-server/minecraft-patches/features/0027-Async-Chunk-Sending.patch b/divinemc-server/minecraft-patches/features/0027-Async-Chunk-Sending.patch index b971cb0..cdd6758 100644 --- a/divinemc-server/minecraft-patches/features/0027-Async-Chunk-Sending.patch +++ b/divinemc-server/minecraft-patches/features/0027-Async-Chunk-Sending.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Async Chunk Sending diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java -index 5cb896334f9916b030ee523119946d3b40585fc3..e93a006cde4dd85a9976e0d6a64643755ba99fb7 100644 +index 636ba1c5fef58aabd5b8d6c6a8d183584b9c8be1..998f8f0bd173ff370e947c16c28b9b01f89da1eb 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java @@ -53,6 +53,8 @@ public final class RegionizedPlayerChunkLoader { @@ -17,7 +17,7 @@ index 5cb896334f9916b030ee523119946d3b40585fc3..e93a006cde4dd85a9976e0d6a6464375 public static void setUnloadDelay(final long ticks) { ((ChunkSystemTicketType)(Object)PLAYER_TICKET_DELAYED).moonrise$setTimeout(Math.max(1, ticks)); } -@@ -428,17 +430,61 @@ public final class RegionizedPlayerChunkLoader { +@@ -421,17 +423,61 @@ public final class RegionizedPlayerChunkLoader { } private void sendChunk(final int chunkX, final int chunkZ) { diff --git a/divinemc-server/minecraft-patches/features/0037-Dynamic-Activation-of-Brain.patch b/divinemc-server/minecraft-patches/features/0037-Dynamic-Activation-of-Brain.patch index 3a46378..dd2b3a5 100644 --- a/divinemc-server/minecraft-patches/features/0037-Dynamic-Activation-of-Brain.patch +++ b/divinemc-server/minecraft-patches/features/0037-Dynamic-Activation-of-Brain.patch @@ -31,10 +31,10 @@ index ca21597263cb430e2a5ae07e8cecfb0d53a270d2..226088405c019922085285ba5d04d7c1 } } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index b4876d35ee6a4e0dab144b471520234157d7173b..00d9e6421185b1ba4f0fdff347a53cae5b830a0a 100644 +index ebd4b7c36e1cece8730782764c476756feebc211..324c573899965b204cec17458b6cb9733d83a868 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -804,6 +804,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -802,6 +802,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.entityTickList .forEach( entity -> { diff --git a/divinemc-server/minecraft-patches/features/0045-Parallel-world-ticking.patch b/divinemc-server/minecraft-patches/features/0045-Parallel-world-ticking.patch index 281e868..0592e28 100644 --- a/divinemc-server/minecraft-patches/features/0045-Parallel-world-ticking.patch +++ b/divinemc-server/minecraft-patches/features/0045-Parallel-world-ticking.patch @@ -4,9 +4,10 @@ Date: Wed, 29 Jan 2025 00:59:03 +0300 Subject: [PATCH] Parallel world ticking Original project: https://github.com/SparklyPower/SparklyPaper +TODO: find the crash problem and fix it (Attempting to remove entity ... from entity slices (.., ..) that is receiving status updates) diff --git a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java -index dce2b0ae83e70ccaf2ac97441f80b25876ee9058..a25db7dd56e31f6a34e4b185b75c727e290e9af1 100644 +index c10e31017e7dfab348e9cc45c28d3858863ac0b1..97bdfe92f32368427bff4960b8f5e39f298c00ab 100644 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java +++ b/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java @@ -1155,7 +1155,7 @@ public final class ChunkHolderManager { @@ -18,7 +19,7 @@ index dce2b0ae83e70ccaf2ac97441f80b25876ee9058..a25db7dd56e31f6a34e4b185b75c727e // These will be handled on the next ServerChunkCache$MainThreadExecutor#pollTask, as it runs the distance manager update // which will invoke processTicketUpdates this.getData().offThreadPendingFullLoadUpdate.addAll(changedFullStatus); // DivineMC - Chunk System optimization -@@ -1187,7 +1187,13 @@ public final class ChunkHolderManager { +@@ -1176,7 +1176,13 @@ public final class ChunkHolderManager { // note: never call while inside the chunk system, this will absolutely break everything public void processUnloads() { @@ -33,7 +34,7 @@ index dce2b0ae83e70ccaf2ac97441f80b25876ee9058..a25db7dd56e31f6a34e4b185b75c727e if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) { throw new IllegalStateException("Cannot unload chunks recursively"); -@@ -1474,7 +1480,7 @@ public final class ChunkHolderManager { +@@ -1463,7 +1469,7 @@ public final class ChunkHolderManager { if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) { throw new IllegalStateException("Cannot update ticket level while unloading chunks or updating entity manager"); } @@ -363,7 +364,7 @@ index 7205fc8d3b17863c262d4c4c3cb956c852468c6f..3cf54630d36f821a232fa03f9094c4c1 } } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd504454fc 100644 +index 324c573899965b204cec17458b6cb9733d83a868..2348a3ec6afb2618033b8f40257f7c9c58448397 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -181,7 +181,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -383,7 +384,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd // CraftBukkit start public final LevelStorageSource.LevelStorageAccess levelStorageAccess; -@@ -681,7 +682,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -680,7 +681,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.sleepStatus = new SleepStatus(); this.gameEventDispatcher = new GameEventDispatcher(this); this.randomSequences = Objects.requireNonNullElseGet(randomSequences, () -> this.getDataStorage().computeIfAbsent(RandomSequences.TYPE)); @@ -392,15 +393,15 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd // Paper start - rewrite chunk system this.moonrise$setEntityLookup(new ca.spottedleaf.moonrise.patches.chunk_system.level.entity.server.ServerEntityLookup((ServerLevel)(Object)this, ((ServerLevel)(Object)this).new EntityCallbacks())); this.chunkTaskScheduler = new ca.spottedleaf.moonrise.patches.chunk_system.scheduling.ChunkTaskScheduler((ServerLevel)(Object)this); -@@ -698,6 +699,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -697,6 +698,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.chunkDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.ChunkDataController((ServerLevel)(Object)this, this.chunkTaskScheduler); // Paper end - rewrite chunk system this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit + this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new org.bxteam.divinemc.server.ServerLevelTickExecutorThreadFactory(getWorld().getName())); // DivineMC - Parallel world ticking this.preciseTime = this.serverLevelData.getDayTime(); // Purpur - Configurable daylight cycle - this.chunkSystemPriorities = new org.bxteam.divinemc.server.chunk.PriorityHandler(this); // DivineMC - Chunk System optimizations } -@@ -1300,12 +1302,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + +@@ -1298,12 +1300,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe if (fluidState.is(fluid)) { fluidState.tick(this, pos, blockState); } @@ -418,7 +419,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd } private void tickBlock(BlockPos pos, Block block) { -@@ -1313,12 +1315,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1311,12 +1313,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe if (blockState.is(block)) { blockState.tick(this, pos, this.random); } @@ -436,7 +437,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd } // Paper start - log detailed entity tick information -@@ -1568,6 +1570,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1566,6 +1568,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } private void addPlayer(ServerPlayer player) { @@ -444,7 +445,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd Entity entity = this.getEntity(player.getUUID()); if (entity != null) { LOGGER.warn("Force-added player with duplicate UUID {}", player.getUUID()); -@@ -1580,7 +1583,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1578,7 +1581,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe // CraftBukkit start private boolean addEntity(Entity entity, @Nullable org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { diff --git a/divinemc-server/minecraft-patches/features/0046-MSPT-Tracking-for-each-world.patch b/divinemc-server/minecraft-patches/features/0046-MSPT-Tracking-for-each-world.patch index 4e914b6..67f77c2 100644 --- a/divinemc-server/minecraft-patches/features/0046-MSPT-Tracking-for-each-world.patch +++ b/divinemc-server/minecraft-patches/features/0046-MSPT-Tracking-for-each-world.patch @@ -25,10 +25,10 @@ index cbeb56539f00a3139f7c19d29cce92fae49dab2f..59642de7b2d3064c59bb1d8d2fc436cb CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world"); serverLevel.fillReportDetails(crashReport); diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 0102d87411dcf0bba7f6873dc54385c957a7e2d7..c87d1ff6f55e2316686add55abebbc7d8ecab914 100644 +index 2348a3ec6afb2618033b8f40257f7c9c58448397..adac2dd1530c21c610f6dced12a80ab726fe3a98 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java -@@ -570,6 +570,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -569,6 +569,12 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe } // Paper end - chunk tick iteration diff --git a/divinemc-server/minecraft-patches/features/0047-Optimize-Raids.patch b/divinemc-server/minecraft-patches/features/0047-Optimize-Raids.patch index 547974e..88c3277 100644 --- a/divinemc-server/minecraft-patches/features/0047-Optimize-Raids.patch +++ b/divinemc-server/minecraft-patches/features/0047-Optimize-Raids.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Optimize Raids diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index c87d1ff6f55e2316686add55abebbc7d8ecab914..690b6d9f89f70afd8f37d907863b87dd1f4591af 100644 +index adac2dd1530c21c610f6dced12a80ab726fe3a98..d39d15dcb6964aed0bf9c2f64952d229d64cff62 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -218,6 +218,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -16,10 +16,10 @@ index c87d1ff6f55e2316686add55abebbc7d8ecab914..690b6d9f89f70afd8f37d907863b87dd @Override public @Nullable LevelChunk getChunkIfLoaded(int x, int z) { -@@ -708,6 +709,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -706,6 +707,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe + this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit this.tickExecutor = java.util.concurrent.Executors.newSingleThreadExecutor(new org.bxteam.divinemc.server.ServerLevelTickExecutorThreadFactory(getWorld().getName())); // DivineMC - Parallel world ticking this.preciseTime = this.serverLevelData.getDayTime(); // Purpur - Configurable daylight cycle - this.chunkSystemPriorities = new org.bxteam.divinemc.server.chunk.PriorityHandler(this); // DivineMC - Chunk System optimizations + this.ominousBanner = Objects.requireNonNullElse(this.registryAccess(), net.minecraft.core.RegistryAccess.EMPTY).lookup(Registries.BANNER_PATTERN).map(Raid::getOminousBannerInstance).orElse(null); // DivineMC - Optimize Raids } diff --git a/divinemc-server/minecraft-patches/features/0053-Regionized-Chunk-Ticking.patch b/divinemc-server/minecraft-patches/features/0053-Regionized-Chunk-Ticking.patch index deccf8d..7d2842b 100644 --- a/divinemc-server/minecraft-patches/features/0053-Regionized-Chunk-Ticking.patch +++ b/divinemc-server/minecraft-patches/features/0053-Regionized-Chunk-Ticking.patch @@ -392,7 +392,7 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies); } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java -index 6edf0d8a4b8b82f85eac4d89cafd24e6730a61c6..83b46b31d1c0b565deeefe3dafa3b0287f14fb00 100644 +index d39d15dcb6964aed0bf9c2f64952d229d64cff62..69b2ce6647edacabdff5079114e067a69d485e96 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -192,7 +192,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -404,7 +404,7 @@ index 6edf0d8a4b8b82f85eac4d89cafd24e6730a61c6..83b46b31d1c0b565deeefe3dafa3b028 volatile boolean isUpdatingNavigations; protected final Raids raids; private final ObjectLinkedOpenHashSet blockEvents = new ObjectLinkedOpenHashSet<>(); -@@ -810,6 +810,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -808,6 +808,13 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.dragonFight.tick(); } @@ -418,7 +418,7 @@ index 6edf0d8a4b8b82f85eac4d89cafd24e6730a61c6..83b46b31d1c0b565deeefe3dafa3b028 io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR this.entityTickList .forEach( -@@ -1817,22 +1824,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe +@@ -1815,22 +1822,16 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe if (Shapes.joinIsNotEmpty(collisionShape, collisionShape1, BooleanOp.NOT_SAME)) { List list = new ObjectArrayList<>(); diff --git a/divinemc-server/paper-patches/features/0005-Chunk-System-Optimizations.patch b/divinemc-server/paper-patches/features/0005-Chunk-System-Optimizations.patch index f4238ec..366f100 100644 --- a/divinemc-server/paper-patches/features/0005-Chunk-System-Optimizations.patch +++ b/divinemc-server/paper-patches/features/0005-Chunk-System-Optimizations.patch @@ -507,15 +507,14 @@ index ab2fa1563d5e32a5313dfcc1da411cab45fb5ca0..1bababc2515d8c805e4ee0c943065f45 } diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java -index 632920e04686d8a0fd0a60e87348be1fe7862a3c..06a0624663a080d8be9f7816fda569fda9fdd1e1 100644 +index 632920e04686d8a0fd0a60e87348be1fe7862a3c..03e7344661b6aea258918bd388dc0e4e6fb5bc96 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java -@@ -3,6 +3,12 @@ package ca.spottedleaf.moonrise.common.util; +@@ -3,6 +3,11 @@ package ca.spottedleaf.moonrise.common.util; import ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool; import ca.spottedleaf.moonrise.common.PlatformHooks; import com.mojang.logging.LogUtils; +import org.bxteam.divinemc.config.DivineConfig; -+import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms; +import org.bxteam.divinemc.server.chunk.TheChunkSystem; +import org.bxteam.divinemc.spark.ThreadDumperRegistry; +import org.bxteam.divinemc.util.ThreadBuilder; @@ -523,18 +522,14 @@ index 632920e04686d8a0fd0a60e87348be1fe7862a3c..06a0624663a080d8be9f7816fda569fd import org.slf4j.Logger; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -@@ -12,83 +18,63 @@ public final class MoonriseCommon { +@@ -12,83 +17,73 @@ public final class MoonriseCommon { private static final Logger LOGGER = LogUtils.getClassLogger(); - public static final PrioritisedThreadPool WORKER_POOL = new PrioritisedThreadPool( - new Consumer<>() { - private final AtomicInteger idGenerator = new AtomicInteger(); -+ public static TheChunkSystem WORKER_POOL; -+ public static TheChunkSystem.ExecutorGroup PARALLEL_GEN_GROUP; -+ public static TheChunkSystem.ExecutorGroup RADIUS_AWARE_GROUP; -+ public static TheChunkSystem.ExecutorGroup LOAD_GROUP; - +- - @Override - public void accept(Thread thread) { - thread.setDaemon(true); @@ -564,29 +559,41 @@ index 632920e04686d8a0fd0a60e87348be1fe7862a3c..06a0624663a080d8be9f7816fda569fd - defaultWorkerThreads = defaultWorkerThreads / 2; - } - defaultWorkerThreads = Integer.getInteger(PlatformHooks.get().getBrand() + ".WorkerThreadCount", Integer.valueOf(defaultWorkerThreads)); -- -- int workerThreads = configWorkerThreads; ++ public static TheChunkSystem WORKER_POOL; ++ public static TheChunkSystem.ExecutorGroup PARALLEL_GEN_GROUP; ++ public static TheChunkSystem.ExecutorGroup RADIUS_AWARE_GROUP; ++ public static TheChunkSystem.ExecutorGroup LOAD_GROUP; + + public static void init(final int configWorkerThreads, final int configIoThreads) { -+ ChunkSystemAlgorithms algorithm = DivineConfig.PerformanceCategory.chunkWorkerAlgorithm; -+ int workerThreads = algorithm.evalWorkers(configWorkerThreads, configIoThreads); -+ int ioThreads = algorithm.evalIO(configWorkerThreads, configIoThreads); + int workerThreads = configWorkerThreads; - if (workerThreads <= 0) { - workerThreads = defaultWorkerThreads; -- } -+ WORKER_POOL = buildChunkSystem(workerThreads); ++ if (configWorkerThreads <= 0) { ++ boolean isWindows = io.netty.util.internal.PlatformDependent.isWindows(); ++ int cpus = Runtime.getRuntime().availableProcessors(); ++ double memGb = Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0; ++ ++ double cpuBased = isWindows ? (cpus / 1.6) : (cpus / 1.3); ++ double memBased = (memGb - 0.5) / 0.6; ++ ++ workerThreads = (int) Math.max(1, Math.min(cpuBased, memBased)); + } - final int ioThreads = Math.max(1, configIoThreads); ++ int ioThreads = Math.max(1, configIoThreads); + +- WORKER_POOL.adjustThreadCount(workerThreads); ++ WORKER_POOL = buildChunkSystem(workerThreads); + PARALLEL_GEN_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(); + RADIUS_AWARE_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(); + LOAD_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(); - -- WORKER_POOL.adjustThreadCount(workerThreads); IO_POOL.adjustThreadCount(ioThreads); -+ LOGGER.info("Running ChunkSystem with {} worker threads and {} I/O threads", workerThreads, ioThreads); -+ } - LOGGER.info(PlatformHooks.get().getBrand() + " is using " + workerThreads + " worker threads, " + ioThreads + " I/O threads"); ++ LOGGER.info("Running ChunkSystem with {} worker threads and {} I/O threads", workerThreads, ioThreads); ++ } ++ + private static @NotNull TheChunkSystem buildChunkSystem(int workerThreads) { + return new TheChunkSystem(workerThreads, new ThreadBuilder() { + @Override @@ -664,7 +671,7 @@ index 559c959aff3c9deef867b9e425fba3e2e669cac6..7d0281cc946d6b0dc6f21fa6798e5320 private MoonriseConstants() {} diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java -index c2b53adb5f0fd8207cf13cb6f7249385b1c30f34..83419bbcbf79d8eed1302d66356a62fa61a33473 100644 +index 17247f177460e89f0413df63d7f3dac2fb1cd197..696d3324a04084600b5d8c8c173b85dbc020d7c0 100644 --- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java +++ b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java @@ -227,7 +227,7 @@ public class GlobalConfiguration extends ConfigurationPart { diff --git a/divinemc-server/paper-patches/features/0007-Configurable-thread-pool-priority.patch b/divinemc-server/paper-patches/features/0007-Configurable-thread-pool-priority.patch index 4103d45..213ae7e 100644 --- a/divinemc-server/paper-patches/features/0007-Configurable-thread-pool-priority.patch +++ b/divinemc-server/paper-patches/features/0007-Configurable-thread-pool-priority.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Configurable thread pool priority diff --git a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java -index 06a0624663a080d8be9f7816fda569fda9fdd1e1..c2a52a071dbb82b8498499b9e9386bdcdfe39c9c 100644 +index 03e7344661b6aea258918bd388dc0e4e6fb5bc96..098b50751d805f03cad5e94e8ed04a20697a51cc 100644 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java +++ b/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java -@@ -66,6 +66,7 @@ public final class MoonriseCommon { +@@ -75,6 +75,7 @@ public final class MoonriseCommon { LOGGER.error("Uncaught exception in thread {}", thread.getName(), throwable); } }); diff --git a/divinemc-server/src/main/java/com/ishland/flowsched/structs/DynamicPriorityQueue.java b/divinemc-server/src/main/java/com/ishland/flowsched/structs/DynamicPriorityQueue.java index 48b62a7..b17a49d 100644 --- a/divinemc-server/src/main/java/com/ishland/flowsched/structs/DynamicPriorityQueue.java +++ b/divinemc-server/src/main/java/com/ishland/flowsched/structs/DynamicPriorityQueue.java @@ -1,20 +1,21 @@ package com.ishland.flowsched.structs; -import org.bxteam.divinemc.server.chunk.PriorityHandler; +import ca.spottedleaf.moonrise.common.util.MoonriseConstants; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicIntegerArray; @SuppressWarnings("unchecked") public class DynamicPriorityQueue { + public static final int MAX_PRIORITY = MoonriseConstants.MAX_VIEW_DISTANCE + 3; private final AtomicIntegerArray taskCount; public final ConcurrentLinkedQueue[] priorities; private final ConcurrentHashMap priorityMap = new ConcurrentHashMap<>(); public DynamicPriorityQueue() { - this.taskCount = new AtomicIntegerArray(PriorityHandler.MAX_PRIORITY + 1); - this.priorities = new ConcurrentLinkedQueue[PriorityHandler.MAX_PRIORITY + 1]; - for (int i = 0; i < (PriorityHandler.MAX_PRIORITY + 1); i++) { + this.taskCount = new AtomicIntegerArray(MAX_PRIORITY); + this.priorities = new ConcurrentLinkedQueue[MAX_PRIORITY]; + for (int i = 0; i < (MAX_PRIORITY); i++) { this.priorities[i] = new ConcurrentLinkedQueue<>(); } } diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java b/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java index ec1f579..ed4da85 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/config/DivineConfig.java @@ -11,8 +11,6 @@ import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.MemoryConfiguration; import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy; import org.bxteam.divinemc.region.LinearImplementation; -import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms; -import org.bxteam.divinemc.server.chunk.ChunkTaskPriority; import org.jetbrains.annotations.Nullable; import org.simpleyaml.configuration.comments.CommentType; import org.simpleyaml.configuration.file.YamlFile; @@ -339,8 +337,6 @@ public class DivineConfig { public static long chunkDataCacheLimit = 32678L; public static int maxViewDistance = 32; public static int playerNearChunkDetectionRange = 128; - public static ChunkSystemAlgorithms chunkWorkerAlgorithm = ChunkSystemAlgorithms.C2ME; - public static ChunkTaskPriority chunkTaskPriority = ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN; public static int threadPoolPriority = Thread.NORM_PRIORITY + 1; public static boolean smoothBedrockLayer = false; public static boolean enableDensityFunctionCompiler = false; @@ -410,17 +406,6 @@ public class DivineConfig { playerNearChunkDetectionRange = 128; } - chunkWorkerAlgorithm = ChunkSystemAlgorithms.valueOf(getString(ConfigCategory.PERFORMANCE.key("chunks.chunk-worker-algorithm"), chunkWorkerAlgorithm.name(), - "Modifies what algorithm the chunk system will use to define thread counts.", - "Valid values:", - " - MOONRISE: Default algorithm, used by default in Paper", - " - C2ME: Algorithm used by C2ME (old)", - " - C2ME_NEW: Modern algorithm used by C2ME")); - chunkTaskPriority = ChunkTaskPriority.valueOf(getString(ConfigCategory.PERFORMANCE.key("chunks.chunk-task-priority"), chunkTaskPriority.name(), - "Sets the algorithm for determining chunk task priorities (generation, loading and etc.).", - "Valid values:", - " - EUCLIDEAN_CIRCLE_PATTERN: Euclidean distance squared algorithm, chunk priorities will be ordered in a circle pattern", - " - DEFAULT_DIAMOND_PATTERN: Default one, chunk priorities will be ordered in a diamond pattern")); threadPoolPriority = getInt(ConfigCategory.PERFORMANCE.key("chunks.thread-pool-priority"), threadPoolPriority, "Sets the priority of the thread pool used for chunk generation"); diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkRunnable.java b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkRunnable.java deleted file mode 100644 index 9db47bc..0000000 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkRunnable.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.bxteam.divinemc.server.chunk; - -import ca.spottedleaf.concurrentutil.util.ConcurrentUtil; -import net.minecraft.server.level.ServerLevel; -import java.lang.invoke.VarHandle; - -public class ChunkRunnable implements Runnable { - public final int chunkX; - public final int chunkZ; - public final ServerLevel world; - private volatile Runnable toRun; - private static final VarHandle TO_RUN_HANDLE = ConcurrentUtil.getVarHandle(ChunkRunnable.class, "toRun", Runnable.class); - - public ChunkRunnable(int chunkX, int chunkZ, ServerLevel world, Runnable run) { - this.chunkX = chunkX; - this.chunkZ = chunkZ; - this.world = world; - this.toRun = run; - } - - public void setRunnable(final Runnable run) { - final Runnable prev = (Runnable)TO_RUN_HANDLE.compareAndExchange(this, (Runnable)null, run); - if (prev != null) { - throw new IllegalStateException("Runnable already set"); - } - } - - @Override - public void run() { - ((Runnable)TO_RUN_HANDLE.getVolatile(this)).run(); - } -} diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemAlgorithms.java b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemAlgorithms.java deleted file mode 100644 index b8c78dc..0000000 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemAlgorithms.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.bxteam.divinemc.server.chunk; - -import ca.spottedleaf.moonrise.common.PlatformHooks; -import io.netty.util.internal.PlatformDependent; -import net.objecthunter.exp4j.ExpressionBuilder; -import net.objecthunter.exp4j.function.Function; -import org.jetbrains.annotations.NotNull; -import oshi.util.tuples.Pair; -import java.util.function.BiFunction; - -public enum ChunkSystemAlgorithms { - MOONRISE((configWorkerThreads, configIoThreads) -> { - int defaultWorkerThreads = Runtime.getRuntime().availableProcessors() / 2; - if (defaultWorkerThreads <= 4) { - defaultWorkerThreads = defaultWorkerThreads <= 3 ? 1 : 2; - } else { - defaultWorkerThreads = defaultWorkerThreads / 2; - } - defaultWorkerThreads = Integer.getInteger(PlatformHooks.get().getBrand() + ".WorkerThreadCount", Integer.valueOf(defaultWorkerThreads)); - - int workerThreads = configWorkerThreads; - - if (workerThreads <= 0) { - workerThreads = defaultWorkerThreads; - } - final int ioThreads = Math.max(1, configIoThreads); - return new Pair<>(workerThreads, ioThreads); - }), - C2ME_NEW((configWorkerThreads, configIoThreads) -> { - String expression = """ - - max( - 1, - min( - if( is_windows, - (cpus / 1.6), - (cpus / 1.3) - ) - if(is_client, 1, 0), - ( ( mem_gb - (if(is_client, 1.0, 0.5)) ) / 0.6 ) - ) - ) - \040"""; - int eval = configWorkerThreads <= 0 ? tryEvaluateExpression(expression) : configWorkerThreads; - return new Pair<>(eval, Math.max(1, configIoThreads)); - }), - C2ME((configWorkerThreads, configIoThreads) -> { - String expression = """ - - max( - 1, - min( - if( is_windows, - (cpus / 1.6 - 2), - (cpus / 1.2 - 2) - ) - if(is_client, 2, 0), - if( is_j9vm, - ( ( mem_gb - (if(is_client, 0.6, 0.2)) ) / 0.4 ), - ( ( mem_gb - (if(is_client, 1.2, 0.6)) ) / 0.6 ) - ) - ) - ) - \040"""; - int eval = configWorkerThreads <= 0 ? tryEvaluateExpression(expression) : configWorkerThreads; - return new Pair<>(eval, Math.max(1, configIoThreads)); - }); - - private final BiFunction> eval; - - ChunkSystemAlgorithms(BiFunction> eval) { - this.eval = eval; - } - - private static int tryEvaluateExpression(String expression) { - return (int) Math.max(1, - new ExpressionBuilder(expression) - .variables("is_windows", "is_j9vm", "is_client", "cpus", "mem_gb") - .function(new Function("max", 2) { - @Override - public double apply(double... args) { - return Math.max(args[0], args[1]); - } - }) - .function(new Function("min", 2) { - @Override - public double apply(double... args) { - return Math.min(args[0], args[1]); - } - }) - .function(new Function("if", 3) { - @Override - public double apply(double... args) { - return args[0] != 0 ? args[1] : args[2]; - } - }) - .build() - .setVariable("is_windows", PlatformDependent.isWindows() ? 1 : 0) - .setVariable("is_j9vm", PlatformDependent.isJ9Jvm() ? 1 : 0) - .setVariable("is_client", 0) - .setVariable("cpus", Runtime.getRuntime().availableProcessors()) - .setVariable("mem_gb", Runtime.getRuntime().maxMemory() / 1024.0 / 1024.0 / 1024.0) - .evaluate() - ); - } - - public int evalWorkers(final int configWorkerThreads, final int configIoThreads) { - return eval.apply(configWorkerThreads, configIoThreads).getA(); - } - - public int evalIO(final int configWorkerThreads, final int configIoThreads) { - return eval.apply(configWorkerThreads, configIoThreads).getB(); - } - - public @NotNull String asDebugString() { - return this + "(" + evalWorkers(-1, -1) + ")"; - } -} diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemTaskQueue.java b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemTaskQueue.java index 2581b37..9842ea2 100644 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemTaskQueue.java +++ b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkSystemTaskQueue.java @@ -3,9 +3,7 @@ package org.bxteam.divinemc.server.chunk; import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor; import ca.spottedleaf.concurrentutil.util.ConcurrentUtil; import ca.spottedleaf.concurrentutil.util.Priority; -import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.executor.RadiusAwarePrioritisedExecutor; -import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.ChunkUpgradeGenericStatusTask; -import ca.spottedleaf.moonrise.patches.chunk_system.scheduling.task.GenericDataLoadTask; + import java.lang.invoke.VarHandle; import java.util.Comparator; import java.util.Map; @@ -152,29 +150,7 @@ public final class ChunkSystemTaskQueue implements PrioritisedExecutor { this.holder = new Holder(this, this.priority.priority, this.subOrder, this.id); ChunkSystemTaskQueue.this.scheduledTasks.getAndIncrement(); - int priority = this.holder.task.priority.priority; - if (this.holder.task.priority.isHigherOrEqualPriority(Priority.BLOCKING)) { - priority = PriorityHandler.BLOCKING; - } else if (this.holder.task.execute instanceof ChunkUpgradeGenericStatusTask upgradeTask) { - int x = upgradeTask.chunkX; - int z = upgradeTask.chunkZ; - priority = upgradeTask.world.chunkSystemPriorities.priority(x, z); - } else if (this.holder.task.execute instanceof RadiusAwarePrioritisedExecutor.Task task) { - int x = task.chunkX; - int z = task.chunkZ; - if (!(x == 0 && z == 0)) { - priority = task.world.chunkSystemPriorities.priority(x, z); - } // else | infinite radius task, ignore. - } else if (this.holder.task.execute instanceof GenericDataLoadTask.ProcessOffMainTask offMainTask) { - int x = offMainTask.loadTask().chunkX; - int z = offMainTask.loadTask().chunkZ; - priority = offMainTask.loadTask().world.chunkSystemPriorities.priority(x, z); - } else if (this.holder.task.execute instanceof ChunkRunnable chunkRunnable) { - int x = chunkRunnable.chunkX; - int z = chunkRunnable.chunkZ; - priority = chunkRunnable.world.chunkSystemPriorities.priority(x, z); - } - ChunkSystemTaskQueue.this.chunkSystem.schedule(this.holder.task.execute, priority); + ChunkSystemTaskQueue.this.chunkSystem.schedule(this.holder.task.execute, this.holder.task.priority.priority); } if (ChunkSystemTaskQueue.this.isShutdown()) { diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java deleted file mode 100644 index 3b3df3b..0000000 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/ChunkTaskPriority.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.bxteam.divinemc.server.chunk; - -public enum ChunkTaskPriority { - EUCLIDEAN_CIRCLE_PATTERN, - DEFAULT_DIAMOND_PATTERN, -} diff --git a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/PriorityHandler.java b/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/PriorityHandler.java deleted file mode 100644 index 88ff0e9..0000000 --- a/divinemc-server/src/main/java/org/bxteam/divinemc/server/chunk/PriorityHandler.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.bxteam.divinemc.server.chunk; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.util.Mth; -import net.minecraft.world.level.ChunkPos; - -import static ca.spottedleaf.moonrise.common.util.MoonriseConstants.MAX_VIEW_DISTANCE; - -public class PriorityHandler { - public static final int MAX_PRIORITY = MAX_VIEW_DISTANCE + 2; - public static final int BLOCKING = 0; - public final ServerLevel level; - - public PriorityHandler(ServerLevel world) { - this.level = world; - } - - public int priority(int chunkX, int chunkZ) { - int priority = MAX_PRIORITY; - for (final ServerPlayer player : this.level.players()) { - ChunkPos playerChunk = player.chunkPosition(); - int playerChunkX = playerChunk.x; - int playerChunkZ = playerChunk.z; - - int dist = Math.max(Mth.abs(playerChunkX - chunkX), Mth.abs(playerChunkZ - chunkZ)); - int distPriority = Math.max(0, MAX_VIEW_DISTANCE - dist); - priority = Math.min(priority, distPriority); - } - return priority; - } -}