9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2026-01-03 22:26:19 +00:00
Files
Leaf/patches/server/0048-Faster-sequencing-of-futures-for-chunk-structure-gen.patch
2024-01-21 08:41:41 -05:00

28 lines
1.4 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
diff --git a/src/main/java/net/minecraft/Util.java b/src/main/java/net/minecraft/Util.java
index 169edd91e25f3c1d27f8a9e2bca58a6143c8a891..3212768d1d8e8922bd88de407add163868837b42 100644
--- a/src/main/java/net/minecraft/Util.java
+++ b/src/main/java/net/minecraft/Util.java
@@ -409,9 +409,11 @@ public class Util {
return futures.get(0).thenApply(List::of);
} else {
CompletableFuture<Void> completableFuture = CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]));
- return completableFuture.thenApply((void_) -> {
- return futures.stream().map(CompletableFuture::join).toList();
- });
+ // Leaf start - Faster sequencing of futures for chunk structure gen
+ return completableFuture.thenCompose((void_) ->
+ CompletableFuture.supplyAsync(() ->
+ futures.stream().map(CompletableFuture::join).toList()));
+ // Leaf end
}
}