mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-20 23:49:31 +00:00
* Region based comment helper functions * (Region based comment) Dont save entity * (Region based comment) Pufferfish DAB * (Region based comment) Cache EntityType * (Region based comment) Cache EntityType * (Region based comment) Pufferfish EntityTTL * (Region based comment) Faster sequence * (Region based comment) FastRNG * (Region based comment) 0042 * (Region based comment) 0721 * (Region based comment) 0009 * (Region based comment) V1rtUal tHReaD * (Region based comment) ZSSM * [ci skip] (Region based comment) 0079 * [ci skip] (Region based comment) 0089 0090 * [ci skip] (Region based comment) 0049 0118 0138 * [ci skip] (Region based comment) 0006 0017 0018 0080 0081 * [ci skip] (Region based comment) 0019 0038 0059 0108 0117 0127 * ALL PATCHES ARE DONE * [ci skip] NZDD
94 lines
5.3 KiB
Diff
94 lines
5.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com>
|
|
Date: Tue, 2 Jan 2024 21:13:53 -0500
|
|
Subject: [PATCH] Faster sequencing of futures for chunk structure gen
|
|
|
|
Replace `thenApply` with `thenCompose`. Once one task is completed then the next task starts immediately,
|
|
to prevent blocking threads while waiting to complete all tasks. But may cause the sequence of future compose disorder.
|
|
|
|
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
|
|
index 0e38a641d8e537750166b56c57aca4a90d418af1..815253d03b85a7a476c1efdeca9496fd64afc137 100644
|
|
--- a/src/main/java/net/minecraft/Util.java
|
|
+++ b/src/main/java/net/minecraft/Util.java
|
|
@@ -490,13 +490,27 @@ public class Util {
|
|
return object;
|
|
}
|
|
|
|
+ // Leaf start - Faster sequencing of futures for chunk structure gen
|
|
public static <V> CompletableFuture<List<V>> sequence(List<? extends CompletableFuture<V>> futures) {
|
|
+ return sequence(futures, false);
|
|
+ }
|
|
+ // Leaf end - Faster sequencing of futures for chunk structure gen
|
|
+
|
|
+ public static <V> CompletableFuture<List<V>> sequence(List<? extends CompletableFuture<V>> futures, boolean useFaster) {
|
|
if (futures.isEmpty()) {
|
|
return CompletableFuture.completedFuture(List.of());
|
|
} else if (futures.size() == 1) {
|
|
return futures.get(0).thenApply(List::of);
|
|
} else {
|
|
CompletableFuture<Void> completableFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
|
|
+ // Leaf start - Faster sequencing of futures for chunk structure gen
|
|
+ if (org.dreeam.leaf.config.modules.opt.FasterStructureGenFutureSequencing.enabled && useFaster) {
|
|
+ return completableFuture.thenCompose(void_ ->
|
|
+ CompletableFuture.supplyAsync(() ->
|
|
+ futures.stream().map(CompletableFuture::join).toList()));
|
|
+ }
|
|
+ // Leaf end
|
|
+
|
|
return completableFuture.thenApply(void_ -> futures.stream().map(CompletableFuture::join).toList());
|
|
}
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java
|
|
index 908431652a0fea79b5a0cee1efd0c7a7d524b614..f4386490897549c898c0755e82bac3b387479e93 100644
|
|
--- a/src/main/java/net/minecraft/server/ReloadableServerRegistries.java
|
|
+++ b/src/main/java/net/minecraft/server/ReloadableServerRegistries.java
|
|
@@ -51,7 +51,7 @@ public class ReloadableServerRegistries {
|
|
List<CompletableFuture<WritableRegistry<?>>> list = LootDataType.values()
|
|
.map(type -> scheduleElementParse((LootDataType<?>)type, registryOps, resourceManager, prepareExecutor, conversions)) // Paper
|
|
.toList();
|
|
- CompletableFuture<List<WritableRegistry<?>>> completableFuture = Util.sequence(list);
|
|
+ CompletableFuture<List<WritableRegistry<?>>> completableFuture = Util.sequence(list, false); // Leaf - Faster sequencing of futures for chunk structure gen
|
|
return completableFuture.thenApplyAsync(registries -> apply(dynamicRegistries, (List<WritableRegistry<?>>)registries), prepareExecutor);
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java b/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
|
index a6b6e5ea191c0e2cd7a2e4f01b89d8af40a83c1b..713fced29fbd819ee6f151c7f3e462f58a21d5e6 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkGeneratorStructureState.java
|
|
@@ -270,7 +270,7 @@ public class ChunkGeneratorStructureState {
|
|
}
|
|
}
|
|
|
|
- return Util.sequence(list).thenApply((list1) -> {
|
|
+ return Util.sequence(list, true).thenApply((list1) -> { // Leaf - Faster sequencing of futures for chunk structure gen
|
|
double d2 = (double) stopwatch.stop().elapsed(TimeUnit.MILLISECONDS) / 1000.0D;
|
|
|
|
ChunkGeneratorStructureState.LOGGER.debug("Calculation for {} took {}s", structureSetEntry, d2);
|
|
diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/FasterStructureGenFutureSequencing.java b/src/main/java/org/dreeam/leaf/config/modules/opt/FasterStructureGenFutureSequencing.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..97a730047491c4ada75963185bb8b2e6f56c56a2
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/FasterStructureGenFutureSequencing.java
|
|
@@ -0,0 +1,21 @@
|
|
+package org.dreeam.leaf.config.modules.opt;
|
|
+
|
|
+import org.dreeam.leaf.config.ConfigModules;
|
|
+import org.dreeam.leaf.config.EnumConfigCategory;
|
|
+
|
|
+public class FasterStructureGenFutureSequencing extends ConfigModules {
|
|
+
|
|
+ public String getBasePath() {
|
|
+ return EnumConfigCategory.PERF.getBaseKeyName();
|
|
+ }
|
|
+
|
|
+ public static boolean enabled = true;
|
|
+
|
|
+ @Override
|
|
+ public void onLoaded() {
|
|
+ enabled = config.getBoolean(getBasePath() + ".faster-structure-gen-future-sequencing", enabled,
|
|
+ config.pickStringRegionBased(
|
|
+ "May cause the inconsistent order of future compose tasks.",
|
|
+ "更快的结构生成任务分段."));
|
|
+ }
|
|
+}
|