9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2025-12-19 14:59:25 +00:00

remove old shit

This commit is contained in:
NONPLAYT
2025-06-29 15:37:48 +03:00
parent cf50ee19bb
commit 880ce4bded
17 changed files with 265 additions and 447 deletions

View File

@@ -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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/ChunkEntitySlices.java
+++ b/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 { @@ -225,8 +225,10 @@ 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
} }
} }
+ 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<Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection>> iterator =
- this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) {
- final Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection> entry = iterator.next();
+ for (final Iterator<Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection>> iterator =
+ this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext(); ) {
+ final Reference2ObjectMap.Entry<Class<? extends Entity>, 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<Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection>> iterator =
- this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext();) {
- final Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection> entry = iterator.next();
+ for (final Iterator<Reference2ObjectMap.Entry<Class<? extends Entity>, EntityCollectionBySection>> iterator =
+ this.entitiesByClass.reference2ObjectEntrySet().fastIterator(); iterator.hasNext(); ) {
+ final Reference2ObjectMap.Entry<Class<? extends Entity>, 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<Entity> into, final Predicate<? super Entity> 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 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 index 2d24d03bbdb5ee0d862cbfff2219f58afffafe12..950b284cb3b4488a794e6c6f936f55ea427ef7cc 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/level/entity/EntityLookup.java --- 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) { 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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/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 { @@ -191,13 +191,13 @@ public final class RegionizedPlayerChunkLoader {
@@ -179,31 +275,22 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b
private int lastChunkX = Integer.MIN_VALUE; private int lastChunkX = Integer.MIN_VALUE;
private int lastChunkZ = 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 centerX = PlayerChunkLoaderData.this.lastChunkX;
final int centerZ = PlayerChunkLoaderData.this.lastChunkZ; 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(c1x - centerX) + Math.abs(c1z - centerZ),
- Math.abs(c2x - centerX) + Math.abs(c2z - centerZ) - Math.abs(c2x - centerX) + Math.abs(c2z - centerZ)
- ); + (c1x - centerX) * (c1x - centerX) + (c1z - centerZ) * (c1z - centerZ),
+ // DivineMC start - Chunk Loading Priority Optimization + (c2x - centerX) * (c2x - centerX) + (c2z - centerZ) * (c2z - centerZ)
+ if (org.bxteam.divinemc.config.DivineConfig.PerformanceCategory.chunkTaskPriority == org.bxteam.divinemc.server.chunk.ChunkTaskPriority.EUCLIDEAN_CIRCLE_PATTERN) { );
+ return Integer.compare( + // DivineMC end - Chunk System Optimization
+ (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
}; };
private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST); private final LongHeapPriorityQueue sendQueue = new LongHeapPriorityQueue(CLOSEST_MANHATTAN_DIST);
private final LongHeapPriorityQueue tickingQueue = 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() { void add() {
@@ -211,7 +298,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b
TickThread.ensureTickThread(this.player, "Cannot add player asynchronously"); TickThread.ensureTickThread(this.player, "Cannot add player asynchronously");
if (this.removed) { if (this.removed) {
throw new IllegalStateException("Adding removed player chunk loader"); 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 // now we can update
this.update(); this.update();
@@ -219,7 +306,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b
} }
private boolean isLoadedChunkGeneratable(final int chunkX, final int chunkZ) { 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() { void remove() {
@@ -227,7 +314,7 @@ index dc2b3ccf7810731c0e2c90e5a476c1c8203a1fb7..5cb896334f9916b030ee523119946d3b
TickThread.ensureTickThread(this.player, "Cannot add player asynchronously"); TickThread.ensureTickThread(this.player, "Cannot add player asynchronously");
if (this.removed) { if (this.removed) {
throw new IllegalStateException("Removing removed player chunk loader"); 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() { 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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
+++ b/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 { @@ -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) { public void saveAllChunks(final boolean flush, final boolean shutdown, final boolean logProgress) {
final List<NewChunkHolder> holders = this.getChunkHolders(); final List<NewChunkHolder> holders = this.getChunkHolders();
@@ -321,13 +338,9 @@ public final class ChunkHolderManager { @@ -323,11 +340,7 @@ public final class ChunkHolderManager {
}
if (logProgress) {
final long currTime = System.nanoTime(); final long currTime = System.nanoTime();
- if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(10L)) { if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(10L)) {
+ if ((currTime - lastLog) > TimeUnit.SECONDS.toNanos(5L)) { // DivineMC - Log a bit more frequently
lastLog = currTime; lastLog = currTime;
- LOGGER.info( - LOGGER.info(
- "Saved " + savedChunk + " block chunks, " + savedEntity + " entity chunks, " + savedPoi - "Saved " + savedChunk + " block chunks, " + savedEntity + " entity chunks, " + savedPoi
@@ -430,23 +514,12 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258
if (!this.sectionToChunkToExpireCount.containsKey(sectionKey)) { if (!this.sectionToChunkToExpireCount.containsKey(sectionKey)) {
// removed concurrently // removed concurrently
@@ -1145,18 +1158,29 @@ public final class ChunkHolderManager { @@ -1145,18 +1158,18 @@ public final class ChunkHolderManager {
if (!TickThread.isTickThread()) { if (!TickThread.isTickThread()) {
// These will be handled on the next ServerChunkCache$MainThreadExecutor#pollTask, as it runs the distance manager update // These will be handled on the next ServerChunkCache$MainThreadExecutor#pollTask, as it runs the distance manager update
// which will invoke processTicketUpdates // which will invoke processTicketUpdates
- this.offThreadPendingFullLoadUpdate.addAll(changedFullStatus); - this.offThreadPendingFullLoadUpdate.addAll(changedFullStatus);
+ this.getData().offThreadPendingFullLoadUpdate.addAll(changedFullStatus); // DivineMC - Chunk System optimization + this.getData().offThreadPendingFullLoadUpdate.addAll(changedFullStatus); // DivineMC - Chunk System optimization
+
+ // DivineMC start - Chunk System optimization
+ this.taskScheduler.scheduleChunkTask(() -> {
+ final java.util.Deque<NewChunkHolder> 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 { } else {
- final ArrayDeque<NewChunkHolder> pendingFullLoadUpdate = this.pendingFullLoadUpdate; - final ArrayDeque<NewChunkHolder> pendingFullLoadUpdate = this.pendingFullLoadUpdate;
+ final java.util.Deque<NewChunkHolder> pendingFullLoadUpdate = this.getData().pendingFullLoadUpdate; // DivineMC - Chunk System optimization + final java.util.Deque<NewChunkHolder> pendingFullLoadUpdate = this.getData().pendingFullLoadUpdate; // DivineMC - Chunk System optimization
@@ -464,7 +537,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258
PlatformHooks.get().onChunkHolderDelete(this.world, holder.vanillaChunkHolder); PlatformHooks.get().onChunkHolderDelete(this.world, holder.vanillaChunkHolder);
this.chunkHolders.remove(CoordinateUtils.getChunkKey(holder.chunkX, holder.chunkZ)); 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 { public enum TicketOperationType {
ADD, REMOVE, ADD_IF_REMOVED, ADD_AND_REMOVE 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 // only call on tick thread
private void processOffThreadFullUpdates() { private void processOffThreadFullUpdates() {
@@ -503,7 +576,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258
NewChunkHolder toUpdate; NewChunkHolder toUpdate;
while ((toUpdate = offThreadPendingFullLoadUpdate.poll()) != null) { while ((toUpdate = offThreadPendingFullLoadUpdate.poll()) != null) {
@@ -1486,7 +1531,7 @@ public final class ChunkHolderManager { @@ -1486,7 +1520,7 @@ public final class ChunkHolderManager {
private boolean processPendingFullUpdate() { private boolean processPendingFullUpdate() {
this.processOffThreadFullUpdates(); this.processOffThreadFullUpdates();
@@ -512,7 +585,7 @@ index 6ce4a98e4d3b633e3c87944c23b6b3f0ff58f159..dce2b0ae83e70ccaf2ac97441f80b258
boolean ret = false; boolean ret = false;
@@ -1522,8 +1567,7 @@ public final class ChunkHolderManager { @@ -1522,8 +1556,7 @@ public final class ChunkHolderManager {
final JsonArray allTicketsJson = new JsonArray(); final JsonArray allTicketsJson = new JsonArray();
ret.add("tickets", allTicketsJson); 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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/NewChunkHolder.java
+++ b/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 { @@ -646,11 +646,19 @@ public final class NewChunkHolder {
@@ -600,11 +673,11 @@ index 2cc0e7c72d2b2e562452138f2b41fd1dcaf0570a..772694b751057aca58cea51741ebc451
this.world = world; this.world = world;
this.chunkX = chunkX; this.chunkX = chunkX;
this.chunkZ = chunkZ; 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.scheduler = scheduler;
this.vanillaChunkHolder = new ChunkHolder( this.vanillaChunkHolder = new ChunkHolder(
new ChunkPos(chunkX, chunkZ), ChunkHolderManager.MAX_TICKET_LEVEL, world, 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 // note: these are completed with null to indicate that no write occurred
// they are also completed with null to indicate a null 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 + // DivineMC end - Chunk System optimization
public static final record UnloadTask(CallbackCompletable<CompoundTag> completable, PrioritisedExecutor.PrioritisedTask task, public static final record UnloadTask(CallbackCompletable<CompoundTag> completable, PrioritisedExecutor.PrioritisedTask task,
- LazyRunnable toRun) {} 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) {
@@ -879,7 +889,11 @@ public final class NewChunkHolder { @@ -879,7 +889,11 @@ public final class NewChunkHolder {
MoonriseRegionFileIO.scheduleSave(this.world, this.chunkX, this.chunkZ, data, type); 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 // 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; return this.requestedGenStatus;
} }
- private final Reference2ObjectOpenHashMap<ChunkStatus, List<Consumer<ChunkAccess>>> statusWaiters = new Reference2ObjectOpenHashMap<>(); - private final Reference2ObjectOpenHashMap<ChunkStatus, List<Consumer<ChunkAccess>>> statusWaiters = new Reference2ObjectOpenHashMap<>();
+ private final Map<ChunkStatus, List<Consumer<ChunkAccess>>> statusWaiters = new java.util.concurrent.ConcurrentHashMap<>(); // DivineMC - Chunk System optimization + private final Reference2ObjectMap<ChunkStatus, List<Consumer<ChunkAccess>>> statusWaiters = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>()); // DivineMC - Chunk System optimization
void addStatusConsumer(final ChunkStatus status, final Consumer<ChunkAccess> consumer) { void addStatusConsumer(final ChunkStatus status, final Consumer<ChunkAccess> consumer) {
this.statusWaiters.computeIfAbsent(status, (final ChunkStatus keyInMap) -> { this.statusWaiters.computeIfAbsent(status, (final ChunkStatus keyInMap) -> {
- return new ArrayList<>(4); @@ -1396,7 +1424,7 @@ public final class NewChunkHolder {
+ return new java.util.concurrent.CopyOnWriteArrayList<>(); // DivineMC - Chunk System optimization
}).add(consumer);
}
@@ -1396,11 +1424,11 @@ public final class NewChunkHolder {
}, Priority.HIGHEST); }, Priority.HIGHEST);
} }
- private final Reference2ObjectOpenHashMap<FullChunkStatus, List<Consumer<LevelChunk>>> fullStatusWaiters = new Reference2ObjectOpenHashMap<>(); - private final Reference2ObjectOpenHashMap<FullChunkStatus, List<Consumer<LevelChunk>>> fullStatusWaiters = new Reference2ObjectOpenHashMap<>();
+ private final Map<FullChunkStatus, List<Consumer<LevelChunk>>> fullStatusWaiters = new java.util.concurrent.ConcurrentHashMap<>(); // DivineMC - Chunk System optimization + private final Reference2ObjectMap<FullChunkStatus, List<Consumer<LevelChunk>>> fullStatusWaiters = it.unimi.dsi.fastutil.objects.Reference2ObjectMaps.synchronize(new Reference2ObjectOpenHashMap<>()); // DivineMC - Chunk System optimization
void addFullStatusConsumer(final FullChunkStatus status, final Consumer<LevelChunk> consumer) { void addFullStatusConsumer(final FullChunkStatus status, final Consumer<LevelChunk> consumer) {
this.fullStatusWaiters.computeIfAbsent(status, (final FullChunkStatus keyInMap) -> { 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 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 index 28ffa653e87a4e8ef7cf614916ef3fe61681fe16..b35b92b204fbefd139c4544f15e32d46bfa30777 100644
--- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/executor/RadiusAwarePrioritisedExecutor.java --- 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 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 @@ -179,6 +179,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -1086,15 +1136,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee
private int lastSpawnChunkRadius; private int lastSpawnChunkRadius;
final EntityTickList entityTickList = new EntityTickList(); final EntityTickList entityTickList = new EntityTickList();
private final ServerWaypointManager waypointManager; private final ServerWaypointManager waypointManager;
@@ -290,6 +291,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -682,6 +683,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
// Paper start - rewrite chunk system // 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.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); 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( this.entityDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController(
new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController.EntityRegionFileStorage( new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.EntityDataController.EntityRegionFileStorage(
new RegionStorageInfo(levelStorageAccess.getLevelId(), dimension, "entities"), new RegionStorageInfo(levelStorageAccess.getLevelId(), dimension, "entities"),
@@ -695,6 +698,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe @@ -825,8 +827,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
@Override @Override
public boolean shouldTickBlocksAt(long chunkPos) { public boolean shouldTickBlocksAt(long chunkPos) {
// Paper start - rewrite chunk system // Paper start - rewrite chunk system
@@ -1120,7 +1154,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee
// Paper end - rewrite chunk system // 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) { private void optimiseRandomTick(final LevelChunk chunk, final int tickSpeed) {
final LevelChunkSection[] sections = chunk.getSections(); final LevelChunkSection[] sections = chunk.getSections();
@@ -1129,7 +1163,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee
final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom; final ca.spottedleaf.moonrise.common.util.SimpleThreadUnsafeRandom simpleRandom = this.simpleRandom;
final boolean doubleTickFluids = !ca.spottedleaf.moonrise.common.PlatformHooks.get().configFixMC224294(); 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 offsetX = cpos.x << 4;
final int offsetZ = cpos.z << 4; final int offsetZ = cpos.z << 4;
@@ -1182,7 +1216,7 @@ index 740f6324eeb4021bc45d27d6145ff71282c761c2..0dbcf9460b27959f99f7a95824b711ee
} }
// Paper end - optimise random ticking // 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) { public boolean isPositionTickingWithEntitiesLoaded(long chunkPos) {
// Paper start - rewrite chunk system // Paper start - rewrite chunk system

View File

@@ -25,7 +25,7 @@ index abfecaf4467092f7baa02e0f5bbfd23d087f2aa3..77a693f42d90b5d17bf56d86b1676247
this.tickCount++; this.tickCount++;
this.tickRateManager.tick(); this.tickRateManager.tick();
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 @@ -216,6 +216,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -36,7 +36,7 @@ index 14c8df2f3b9c133b38e871e81f7ee2333322437c..05b8834b5566ac12655b563a1a58f123
@Override @Override
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) { 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(); this.updateSkyBrightness();
if (runsNormally) { if (runsNormally) {
this.tickTime(); 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); this.setDayTime(this.preciseTime);
} else } else
// Purpur end - Configurable daylight cycle // Purpur end - Configurable daylight cycle
@@ -66,7 +66,7 @@ index 14c8df2f3b9c133b38e871e81f7ee2333322437c..05b8834b5566ac12655b563a1a58f123
this.serverLevelData.setDayTime(time); this.serverLevelData.setDayTime(time);
// Purpur start - Configurable daylight cycle // Purpur start - Configurable daylight cycle
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java 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 --- a/net/minecraft/world/entity/LivingEntity.java
+++ b/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 @@ -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<GameRules.BooleanValue> { public static class BooleanValue extends GameRules.Value<GameRules.BooleanValue> {
private boolean value; private boolean value;
diff --git a/net/minecraft/world/level/block/state/BlockBehaviour.java b/net/minecraft/world/level/block/state/BlockBehaviour.java 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 --- a/net/minecraft/world/level/block/state/BlockBehaviour.java
+++ b/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 { @@ -347,13 +347,21 @@ public abstract class BlockBehaviour implements FeatureElement {

View File

@@ -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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/player/RegionizedPlayerChunkLoader.java
+++ b/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 { @@ -53,6 +53,8 @@ public final class RegionizedPlayerChunkLoader {
@@ -17,7 +17,7 @@ index 5cb896334f9916b030ee523119946d3b40585fc3..e93a006cde4dd85a9976e0d6a6464375
public static void setUnloadDelay(final long ticks) { public static void setUnloadDelay(final long ticks) {
((ChunkSystemTicketType)(Object)PLAYER_TICKET_DELAYED).moonrise$setTimeout(Math.max(1, 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) { private void sendChunk(final int chunkX, final int chunkZ) {

View File

@@ -31,10 +31,10 @@ index ca21597263cb430e2a5ae07e8cecfb0d53a270d2..226088405c019922085285ba5d04d7c1
} }
} }
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 this.entityTickList
.forEach( .forEach(
entity -> { entity -> {

View File

@@ -4,9 +4,10 @@ Date: Wed, 29 Jan 2025 00:59:03 +0300
Subject: [PATCH] Parallel world ticking Subject: [PATCH] Parallel world ticking
Original project: https://github.com/SparklyPower/SparklyPaper 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 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 --- a/ca/spottedleaf/moonrise/patches/chunk_system/scheduling/ChunkHolderManager.java
+++ b/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 { @@ -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 // These will be handled on the next ServerChunkCache$MainThreadExecutor#pollTask, as it runs the distance manager update
// which will invoke processTicketUpdates // which will invoke processTicketUpdates
this.getData().offThreadPendingFullLoadUpdate.addAll(changedFullStatus); // DivineMC - Chunk System optimization 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 // note: never call while inside the chunk system, this will absolutely break everything
public void processUnloads() { public void processUnloads() {
@@ -33,7 +34,7 @@ index dce2b0ae83e70ccaf2ac97441f80b25876ee9058..a25db7dd56e31f6a34e4b185b75c727e
if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) { if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) {
throw new IllegalStateException("Cannot unload chunks recursively"); 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) { if (BLOCK_TICKET_UPDATES.get() == Boolean.TRUE) {
throw new IllegalStateException("Cannot update ticket level while unloading chunks or updating entity manager"); 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 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 @@ -181,7 +181,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -383,7 +384,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd
// CraftBukkit start // CraftBukkit start
public final LevelStorageSource.LevelStorageAccess levelStorageAccess; 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.sleepStatus = new SleepStatus();
this.gameEventDispatcher = new GameEventDispatcher(this); this.gameEventDispatcher = new GameEventDispatcher(this);
this.randomSequences = Objects.requireNonNullElseGet(randomSequences, () -> this.getDataStorage().computeIfAbsent(RandomSequences.TYPE)); this.randomSequences = Objects.requireNonNullElseGet(randomSequences, () -> this.getDataStorage().computeIfAbsent(RandomSequences.TYPE));
@@ -392,15 +393,15 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd
// Paper start - rewrite chunk system // 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.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); 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); this.chunkDataController = new ca.spottedleaf.moonrise.patches.chunk_system.io.datacontroller.ChunkDataController((ServerLevel)(Object)this, this.chunkTaskScheduler);
// Paper end - rewrite chunk system // Paper end - rewrite chunk system
this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit 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.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.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)) { if (fluidState.is(fluid)) {
fluidState.tick(this, pos, blockState); fluidState.tick(this, pos, blockState);
} }
@@ -418,7 +419,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd
} }
private void tickBlock(BlockPos pos, Block block) { 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)) { if (blockState.is(block)) {
blockState.tick(this, pos, this.random); blockState.tick(this, pos, this.random);
} }
@@ -436,7 +437,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd
} }
// Paper start - log detailed entity tick information // 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) { private void addPlayer(ServerPlayer player) {
@@ -444,7 +445,7 @@ index 00d9e6421185b1ba4f0fdff347a53cae5b830a0a..c3ed824b2c31902b50de74df37d9d8fd
Entity entity = this.getEntity(player.getUUID()); Entity entity = this.getEntity(player.getUUID());
if (entity != null) { if (entity != null) {
LOGGER.warn("Force-added player with duplicate UUID {}", player.getUUID()); 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 // CraftBukkit start
private boolean addEntity(Entity entity, @Nullable org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) { private boolean addEntity(Entity entity, @Nullable org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason spawnReason) {

View File

@@ -25,10 +25,10 @@ index cbeb56539f00a3139f7c19d29cce92fae49dab2f..59642de7b2d3064c59bb1d8d2fc436cb
CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world"); CrashReport crashReport = CrashReport.forThrowable(levelTickingException, "Exception ticking world");
serverLevel.fillReportDetails(crashReport); serverLevel.fillReportDetails(crashReport);
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 // Paper end - chunk tick iteration

View File

@@ -5,7 +5,7 @@ Subject: [PATCH] Optimize Raids
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 @@ -218,6 +218,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -16,10 +16,10 @@ index c87d1ff6f55e2316686add55abebbc7d8ecab914..690b6d9f89f70afd8f37d907863b87dd
@Override @Override
public @Nullable LevelChunk getChunkIfLoaded(int x, int z) { 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.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.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 + this.ominousBanner = Objects.requireNonNullElse(this.registryAccess(), net.minecraft.core.RegistryAccess.EMPTY).lookup(Registries.BANNER_PATTERN).map(Raid::getOminousBannerInstance).orElse(null); // DivineMC - Optimize Raids
} }

View File

@@ -392,7 +392,7 @@ index 3cf54630d36f821a232fa03f9094c4c1f70902a1..5f62eee8a60d7fcadb1f9efb7473bc5c
this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies); this.level.tickCustomSpawners(this.spawnEnemies, this.spawnFriendlies);
} }
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java 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 --- a/net/minecraft/server/level/ServerLevel.java
+++ b/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 @@ -192,7 +192,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
@@ -404,7 +404,7 @@ index 6edf0d8a4b8b82f85eac4d89cafd24e6730a61c6..83b46b31d1c0b565deeefe3dafa3b028
volatile boolean isUpdatingNavigations; volatile boolean isUpdatingNavigations;
protected final Raids raids; protected final Raids raids;
private final ObjectLinkedOpenHashSet<BlockEventData> blockEvents = new ObjectLinkedOpenHashSet<>(); private final ObjectLinkedOpenHashSet<BlockEventData> 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(); this.dragonFight.tick();
} }
@@ -418,7 +418,7 @@ index 6edf0d8a4b8b82f85eac4d89cafd24e6730a61c6..83b46b31d1c0b565deeefe3dafa3b028
io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR io.papermc.paper.entity.activation.ActivationRange.activateEntities(this); // Paper - EAR
this.entityTickList this.entityTickList
.forEach( .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)) { if (Shapes.joinIsNotEmpty(collisionShape, collisionShape1, BooleanOp.NOT_SAME)) {
List<PathNavigation> list = new ObjectArrayList<>(); List<PathNavigation> list = new ObjectArrayList<>();

View File

@@ -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 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 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java
+++ b/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.concurrentutil.executor.thread.PrioritisedThreadPool;
import ca.spottedleaf.moonrise.common.PlatformHooks; import ca.spottedleaf.moonrise.common.PlatformHooks;
import com.mojang.logging.LogUtils; import com.mojang.logging.LogUtils;
+import org.bxteam.divinemc.config.DivineConfig; +import org.bxteam.divinemc.config.DivineConfig;
+import org.bxteam.divinemc.server.chunk.ChunkSystemAlgorithms;
+import org.bxteam.divinemc.server.chunk.TheChunkSystem; +import org.bxteam.divinemc.server.chunk.TheChunkSystem;
+import org.bxteam.divinemc.spark.ThreadDumperRegistry; +import org.bxteam.divinemc.spark.ThreadDumperRegistry;
+import org.bxteam.divinemc.util.ThreadBuilder; +import org.bxteam.divinemc.util.ThreadBuilder;
@@ -523,18 +522,14 @@ index 632920e04686d8a0fd0a60e87348be1fe7862a3c..06a0624663a080d8be9f7816fda569fd
import org.slf4j.Logger; import org.slf4j.Logger;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; 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(); private static final Logger LOGGER = LogUtils.getClassLogger();
- public static final PrioritisedThreadPool WORKER_POOL = new PrioritisedThreadPool( - public static final PrioritisedThreadPool WORKER_POOL = new PrioritisedThreadPool(
- new Consumer<>() { - new Consumer<>() {
- private final AtomicInteger idGenerator = new AtomicInteger(); - 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 - @Override
- public void accept(Thread thread) { - public void accept(Thread thread) {
- thread.setDaemon(true); - thread.setDaemon(true);
@@ -564,29 +559,41 @@ index 632920e04686d8a0fd0a60e87348be1fe7862a3c..06a0624663a080d8be9f7816fda569fd
- defaultWorkerThreads = defaultWorkerThreads / 2; - defaultWorkerThreads = defaultWorkerThreads / 2;
- } - }
- defaultWorkerThreads = Integer.getInteger(PlatformHooks.get().getBrand() + ".WorkerThreadCount", Integer.valueOf(defaultWorkerThreads)); - defaultWorkerThreads = Integer.getInteger(PlatformHooks.get().getBrand() + ".WorkerThreadCount", Integer.valueOf(defaultWorkerThreads));
- + public static TheChunkSystem WORKER_POOL;
- int workerThreads = configWorkerThreads; + 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) { + public static void init(final int configWorkerThreads, final int configIoThreads) {
+ ChunkSystemAlgorithms algorithm = DivineConfig.PerformanceCategory.chunkWorkerAlgorithm; int workerThreads = configWorkerThreads;
+ int workerThreads = algorithm.evalWorkers(configWorkerThreads, configIoThreads);
+ int ioThreads = algorithm.evalIO(configWorkerThreads, configIoThreads);
- if (workerThreads <= 0) { - if (workerThreads <= 0) {
- workerThreads = defaultWorkerThreads; - workerThreads = defaultWorkerThreads;
- } + if (configWorkerThreads <= 0) {
+ WORKER_POOL = buildChunkSystem(workerThreads); + 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); - 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(); + PARALLEL_GEN_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup();
+ RADIUS_AWARE_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(); + RADIUS_AWARE_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup();
+ LOAD_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup(); + LOAD_GROUP = MoonriseCommon.WORKER_POOL.createExecutorGroup();
- WORKER_POOL.adjustThreadCount(workerThreads);
IO_POOL.adjustThreadCount(ioThreads); 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(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) { + private static @NotNull TheChunkSystem buildChunkSystem(int workerThreads) {
+ return new TheChunkSystem(workerThreads, new ThreadBuilder() { + return new TheChunkSystem(workerThreads, new ThreadBuilder() {
+ @Override + @Override
@@ -664,7 +671,7 @@ index 559c959aff3c9deef867b9e425fba3e2e669cac6..7d0281cc946d6b0dc6f21fa6798e5320
private MoonriseConstants() {} private MoonriseConstants() {}
diff --git a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java b/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java 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 --- a/src/main/java/io/papermc/paper/configuration/GlobalConfiguration.java
+++ b/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 { @@ -227,7 +227,7 @@ public class GlobalConfiguration extends ConfigurationPart {

View File

@@ -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 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 --- a/src/main/java/ca/spottedleaf/moonrise/common/util/MoonriseCommon.java
+++ b/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); LOGGER.error("Uncaught exception in thread {}", thread.getName(), throwable);
} }
}); });

View File

@@ -1,20 +1,21 @@
package com.ishland.flowsched.structs; 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.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicIntegerArray; import java.util.concurrent.atomic.AtomicIntegerArray;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public class DynamicPriorityQueue<E> { public class DynamicPriorityQueue<E> {
public static final int MAX_PRIORITY = MoonriseConstants.MAX_VIEW_DISTANCE + 3;
private final AtomicIntegerArray taskCount; private final AtomicIntegerArray taskCount;
public final ConcurrentLinkedQueue<E>[] priorities; public final ConcurrentLinkedQueue<E>[] priorities;
private final ConcurrentHashMap<E, Integer> priorityMap = new ConcurrentHashMap<>(); private final ConcurrentHashMap<E, Integer> priorityMap = new ConcurrentHashMap<>();
public DynamicPriorityQueue() { public DynamicPriorityQueue() {
this.taskCount = new AtomicIntegerArray(PriorityHandler.MAX_PRIORITY + 1); this.taskCount = new AtomicIntegerArray(MAX_PRIORITY);
this.priorities = new ConcurrentLinkedQueue[PriorityHandler.MAX_PRIORITY + 1]; this.priorities = new ConcurrentLinkedQueue[MAX_PRIORITY];
for (int i = 0; i < (PriorityHandler.MAX_PRIORITY + 1); i++) { for (int i = 0; i < (MAX_PRIORITY); i++) {
this.priorities[i] = new ConcurrentLinkedQueue<>(); this.priorities[i] = new ConcurrentLinkedQueue<>();
} }
} }

View File

@@ -11,8 +11,6 @@ import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.MemoryConfiguration; import org.bukkit.configuration.MemoryConfiguration;
import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy; import org.bxteam.divinemc.entity.pathfinding.PathfindTaskRejectPolicy;
import org.bxteam.divinemc.region.LinearImplementation; 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.jetbrains.annotations.Nullable;
import org.simpleyaml.configuration.comments.CommentType; import org.simpleyaml.configuration.comments.CommentType;
import org.simpleyaml.configuration.file.YamlFile; import org.simpleyaml.configuration.file.YamlFile;
@@ -339,8 +337,6 @@ public class DivineConfig {
public static long chunkDataCacheLimit = 32678L; public static long chunkDataCacheLimit = 32678L;
public static int maxViewDistance = 32; public static int maxViewDistance = 32;
public static int playerNearChunkDetectionRange = 128; 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 int threadPoolPriority = Thread.NORM_PRIORITY + 1;
public static boolean smoothBedrockLayer = false; public static boolean smoothBedrockLayer = false;
public static boolean enableDensityFunctionCompiler = false; public static boolean enableDensityFunctionCompiler = false;
@@ -410,17 +406,6 @@ public class DivineConfig {
playerNearChunkDetectionRange = 128; 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, threadPoolPriority = getInt(ConfigCategory.PERFORMANCE.key("chunks.thread-pool-priority"), threadPoolPriority,
"Sets the priority of the thread pool used for chunk generation"); "Sets the priority of the thread pool used for chunk generation");

View File

@@ -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();
}
}

View File

@@ -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<Integer, Integer, Pair<Integer, Integer>> eval;
ChunkSystemAlgorithms(BiFunction<Integer, Integer, Pair<Integer, Integer>> 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) + ")";
}
}

View File

@@ -3,9 +3,7 @@ package org.bxteam.divinemc.server.chunk;
import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor; import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor;
import ca.spottedleaf.concurrentutil.util.ConcurrentUtil; import ca.spottedleaf.concurrentutil.util.ConcurrentUtil;
import ca.spottedleaf.concurrentutil.util.Priority; 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.lang.invoke.VarHandle;
import java.util.Comparator; import java.util.Comparator;
import java.util.Map; 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); this.holder = new Holder(this, this.priority.priority, this.subOrder, this.id);
ChunkSystemTaskQueue.this.scheduledTasks.getAndIncrement(); ChunkSystemTaskQueue.this.scheduledTasks.getAndIncrement();
int priority = this.holder.task.priority.priority; ChunkSystemTaskQueue.this.chunkSystem.schedule(this.holder.task.execute, 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);
} }
if (ChunkSystemTaskQueue.this.isShutdown()) { if (ChunkSystemTaskQueue.this.isShutdown()) {

View File

@@ -1,6 +0,0 @@
package org.bxteam.divinemc.server.chunk;
public enum ChunkTaskPriority {
EUCLIDEAN_CIRCLE_PATTERN,
DEFAULT_DIAMOND_PATTERN,
}

View File

@@ -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;
}
}