Skip to content
This repository has been archived by the owner on Jun 19, 2021. It is now read-only.

Threaded WorldGen #375

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2c205e0
on the latest version now
Titaniumtown Apr 6, 2021
be67395
update
Titaniumtown Apr 6, 2021
b2d81c1
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/Yatopia into stagin…
Titaniumtown Apr 8, 2021
6fdd4e2
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 8, 2021
8527a0c
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/Yatopia into stagin…
Titaniumtown Apr 12, 2021
b158a87
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/Yatopia into stagin…
Titaniumtown Apr 12, 2021
133e09c
MEGA port PR (#459)
Titaniumtown Apr 12, 2021
4b58475
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/Yatopia into stagin…
Titaniumtown Apr 12, 2021
3ebe72c
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 12, 2021
5511113
update README.md and LICENSE.md
Titaniumtown Apr 13, 2021
81fa176
forgot about tic-tacs!
Titaniumtown Apr 13, 2021
c42517c
...and AI-Improvements
Titaniumtown Apr 13, 2021
0fcae7c
give JellySquid credit for lithium-gen.patch
Titaniumtown Apr 13, 2021
e57142a
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 13, 2021
63713d3
re-add lithium-skip-ticking-block-entities-that-are-doing-n.patch
Titaniumtown Apr 13, 2021
3c54591
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/Yatopia into stagin…
Titaniumtown Apr 13, 2021
1136c04
drop AI-improvements
Titaniumtown Apr 13, 2021
1bbceb8
rebuild
Titaniumtown Apr 13, 2021
e750b07
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 13, 2021
22fae2c
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/Yatopia into stagin…
Titaniumtown Apr 15, 2021
824dab7
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 15, 2021
de73ba1
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 21, 2021
d479b55
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 21, 2021
4290701
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 21, 2021
8e6a62a
Merge branch 'staging/1.16.5' of github.com:YatopiaMC/Yatopia into de…
Titaniumtown Apr 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PATCHES.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ This is an overview over all patches that are currently used.
| server | Custom Locale Support | Zoe | |
| server | Custom table implementation for blockstate state lookups | Spottedleaf | |
| server | Customizable wither health and healing | jmp | |
| server | Decompile fixes for WorldChunkManagerMultiNoise | ishland | |
| api | Default permissions | William Blake Galbreath | |
| server | Delay chunk unloads | Spottedleaf | |
| server | Despawn rate config options per projectile type | jmp | |
Expand Down Expand Up @@ -220,6 +221,7 @@ This is an overview over all patches that are currently used.
| server | Fix the dead lagging the server | William Blake Galbreath | |
| server | Fix vanilla command permission handler | William Blake Galbreath | |
| server | Flying squids! Oh my! | William Blake Galbreath | |
| server | Force world save | ishland | |
| server | Full netherite armor grants fire resistance | BillyGalbreath | |
| api | Full netherite armor grants fire resistance | BillyGalbreath | |
| server | Giants AI settings | William Blake Galbreath | |
Expand Down Expand Up @@ -282,6 +284,8 @@ This is an overview over all patches that are currently used.
| server | Movement options for armor stands | Mariell Hoversholm | |
| server | Multi-Threaded Server Ticking Vanilla | Spottedleaf | |
| server | Multi-Threaded ticking CraftBukkit | Spottedleaf | |
| server | Multi-threaded RegionFile IO | ishland | |
| server | Multi-threaded World Upgrade | ishland | |
| server | Multithreaded Entity Tracker fixup | Simon Gardling | |
| server | Multithreaded entity tracking | Paul Sauve | |
| server | Name craft scheduler threads according to the plugin using | Spottedleaf | |
Expand Down Expand Up @@ -403,6 +407,7 @@ This is an overview over all patches that are currently used.
| api | Suspected plugins report | ishland | |
| server | Swap priority of checks in chunk ticking | Paul Sauve | |
| server | Swaps the predicate order of collision | ㄗㄠˋ ㄑㄧˊ | |
| server | Threaded WorldGen | ishland | |
| server | Tick fluids config | BillyGalbreath | |
| server | Time scoreboard search | Spottedleaf | |
| server | Timings stuff | William Blake Galbreath | |
Expand Down Expand Up @@ -430,11 +435,14 @@ This is an overview over all patches that are currently used.
| server | Zombie horse naturally spawn | William Blake Galbreath | |
| server | add config for logging login location | Simon Gardling | |
| server | dont load chunks for physics | Aikar | |
| server | fixup! Threaded WorldGen | ishland | |
| server | fixup! Threaded WorldGen | ishland | |
| server | lithium DataTrackerMixin | JellySquid | tr7zw |
| server | lithium HashedList | JellySquid | |
| server | lithium MixinBox | JellySquid | |
| server | lithium MixinDirection | JellySquid | |
| server | lithium MixinGoalSelector | JellySquid | |
| server | lithium MultiNoiseBiomeSourceMixin | SuperCoder7979 | |
| server | lithium NoiseChunkGeneratorMixin | JellySquid | |
| server | lithium PerlinNoiseSamplerMixin | JellySquid | Bud Gidiere |
| server | lithium VoronoiBiomeAccessTypeMixin | JellySquid | |
Expand Down
472 changes: 472 additions & 0 deletions patches/server/0071-Threaded-WorldGen.patch

Large diffs are not rendered by default.

298 changes: 298 additions & 0 deletions patches/server/0072-Multi-threaded-RegionFile-IO.patch

Large diffs are not rendered by default.

144 changes: 144 additions & 0 deletions patches/server/0073-Multi-threaded-World-Upgrade.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: ishland <[email protected]>
Date: Fri, 5 Feb 2021 19:34:00 +0800
Subject: [PATCH] Multi-threaded World Upgrade


diff --git a/src/main/java/net/minecraft/server/Main.java b/src/main/java/net/minecraft/server/Main.java
index 6818f8496ab76ee6ffc747bd6848b43830ec8914..1fe2610ed0ddab1e203e273914c9325aec74e7c2 100644
--- a/src/main/java/net/minecraft/server/Main.java
+++ b/src/main/java/net/minecraft/server/Main.java
@@ -281,6 +281,8 @@ public class Main {
WorldUpgrader worldupgrader = new WorldUpgrader(convertable_conversionsession, datafixer, immutableset, flag);
IChatBaseComponent ichatbasecomponent = null;

+ long lastLocation = 0L; // Yatopia
+ long lastTime = System.nanoTime(); // Yatopia
while (!worldupgrader.b()) {
IChatBaseComponent ichatbasecomponent1 = worldupgrader.h();

@@ -289,13 +291,16 @@ public class Main {
Main.LOGGER.info(worldupgrader.h().getString());
}

- int i = worldupgrader.e();
-
- if (i > 0) {
- int j = worldupgrader.f() + worldupgrader.g();
-
- Main.LOGGER.info("{}% completed ({} / {} chunks)...", MathHelper.d((float) j / (float) i * 100.0F), j, i);
- }
+ // Yatopia start
+ long totalChunkCount = worldupgrader.getTotalChunkCount();
+ if (totalChunkCount > 0) {
+ long processedCount = worldupgrader.getUpgradedChunkCount() + worldupgrader.getSkippedChunkCount();
+ long currentTime = System.nanoTime();
+ String speedRate = String.format("%.1f", (processedCount - lastLocation) / ((currentTime - lastTime) / 1_000_000_000.0));
+ Main.LOGGER.info("{}% completed ({} / {} chunks) at {}cps...", MathHelper.d((float) processedCount / (float) totalChunkCount * 100.0F), processedCount, totalChunkCount, speedRate);
+ lastLocation = processedCount;
+ lastTime = currentTime;
+ } // Yatopia end

if (!booleansupplier.getAsBoolean()) {
worldupgrader.a();
diff --git a/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java b/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java
index 6725b31a5183d5af7f8f7566ed21eb61797ef4c9..f13e16aca89f5013ef316e7dbf3d4c67885e6f3e 100644
--- a/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java
+++ b/src/main/java/net/minecraft/util/worldupdate/WorldUpgrader.java
@@ -33,6 +33,13 @@ import net.minecraft.world.level.storage.Convertable;
import net.minecraft.world.level.storage.WorldPersistentData;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
+// Yatopia start
+import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+// Yatopia end

// CraftBukkit start
import net.minecraft.world.level.dimension.DimensionManager;
@@ -50,9 +57,9 @@ public class WorldUpgrader {
private volatile boolean h = true;
private volatile boolean i;
private volatile float j;
- private volatile int k;
- private volatile int l;
- private volatile int m;
+ private volatile long k; // Yatopia - int -> long
+ private volatile long l; // Yatopia - int -> long
+ private volatile long m; // Yatopia - int -> long
private final Object2FloatMap<ResourceKey<DimensionManager>> n = Object2FloatMaps.synchronize(new Object2FloatOpenCustomHashMap(SystemUtils.k())); // CraftBukkit
private volatile IChatBaseComponent o = new ChatMessage("optimizeWorld.stage.counting");
private static final Pattern p = Pattern.compile("^r\\.(-?[0-9]+)\\.(-?[0-9]+)\\.mca$");
@@ -117,6 +124,11 @@ public class WorldUpgrader {

this.o = new ChatMessage("optimizeWorld.stage.upgrading");

+ // Yatopia start
+ final ExecutorService upgradeExecutor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors(), new ThreadFactoryBuilder().setDaemon(true).setPriority(Thread.NORM_PRIORITY - 1).setNameFormat("WorldUpgrader Worker #%d").build());
+ final Set<CompletableFuture<Void>> futures = new ObjectOpenHashSet<>();
+ final com.ibm.asyncutil.locks.AsyncNamedLock<Integer> regionFileLocks = com.ibm.asyncutil.locks.AsyncNamedLock.createFair();
+ // Yatopia end
while (this.h) {
boolean flag = false;
float f1 = 0.0F;
@@ -130,6 +142,11 @@ public class WorldUpgrader {

if (listiterator.hasNext()) {
ChunkCoordIntPair chunkcoordintpair = (ChunkCoordIntPair) listiterator.next();
+ // Yatopia start
+ flag = true;
+ futures.add(regionFileLocks.acquireLock(String.format("%d %d", chunkcoordintpair.getRegionX(), chunkcoordintpair.getRegionZ()).hashCode()).toCompletableFuture().thenAcceptAsync(lockToken -> {
+ try {
+ // Yatopia end
boolean flag1 = false;

try {
@@ -179,7 +196,12 @@ public class WorldUpgrader {
++this.m;
}

- flag = true;
+ // Yatopia start
+ } finally {
+ lockToken.releaseLock();
+ }
+ }, upgradeExecutor));
+ // Yatopia end
}

f2 = (float) listiterator.nextIndex() / f;
@@ -192,6 +214,8 @@ public class WorldUpgrader {
}
}

+ CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); // Yatopia
+ upgradeExecutor.shutdown(); // Yatopia
this.o = new ChatMessage("optimizeWorld.stage.finished");
UnmodifiableIterator unmodifiableiterator3 = immutablemap1.values().iterator();

@@ -280,16 +304,19 @@ public class WorldUpgrader {
}

public int e() {
- return this.k;
+ return (int) this.k; // Yatopia
}
+ public long getTotalChunkCount() { return this.k; } // Yatopia

public int f() {
- return this.l;
+ return (int) this.l; // Yatopia
}
+ public long getUpgradedChunkCount() { return this.l; } // Yatopia

public int g() {
- return this.m;
+ return (int) this.m; // Yatopia
}
+ public long getSkippedChunkCount() { return this.m; } // Yatopia

public IChatBaseComponent h() {
return this.o;
Loading