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 b40864e41e1506884fdefefbf3cf4833a8f706c3..4b52a487296c8ea4d4159ec74582f13eb3ffbe36 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 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 } }