port Significantly improve performance of the end generation (#7919)

This commit is contained in:
Owen 2022-06-10 10:11:41 -04:00 committed by GitHub
parent cf384f5269
commit a8a01bbb52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
382 changed files with 110 additions and 112 deletions

View File

@ -1,65 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: SuperCoder7979 <25208576+SuperCoder7979@users.noreply.github.com>
Date: Tue, 3 Nov 2020 23:48:05 -0600
Subject: [PATCH] Significantly improve performance of the end generation
This patch implements a noise cache for the end which significantly reduces the computation time of generation. This results in about a 3x improvement.
Original code by SuperCoder7979 and Gegy in Lithium, licensed under LGPL-3.0 (Source: https://github.com/jellysquid3/lithium-fabric)
Co-authored-by: Gegy <gegy1000@gmail.com>
Co-authored-by: Dylan Xaldin <Puremin0rez515@gmail.com>
Co-authored-by: pop4959 <pop4959@gmail.com>
1.19: Not compatible. Was removed from lithium a while ago I think (see https://github.com/CaffeineMC/lithium-fabric/commit/94cffd161193bf51b7986379bb77b3f97e7c25d2) -MM
diff --git a/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java b/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java
index 3f9127f93c9720c89b578d36a1bcdb89fc01222a..9004d9d7dcb1466047da62d0a6d01e7b4ac6a216 100644
--- a/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java
+++ b/src/main/java/net/minecraft/world/level/biome/TheEndBiomeSource.java
@@ -29,6 +29,16 @@ public class TheEndBiomeSource extends BiomeSource {
private final Holder<Biome> midlands;
private final Holder<Biome> islands;
private final Holder<Biome> barrens;
+ // Paper start
+ private static final class NoiseCache {
+ public long[] keys = new long[8192];
+ public float[] values = new float[8192];
+ public NoiseCache() {
+ java.util.Arrays.fill(keys, Long.MIN_VALUE);
+ }
+ }
+ private static final ThreadLocal<java.util.Map<SimplexNoise, NoiseCache>> noiseCache = ThreadLocal.withInitial(java.util.WeakHashMap::new);
+ // Paper end
public TheEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
this(seed, biomeRegistry.getOrCreateHolder(Biomes.THE_END), biomeRegistry.getOrCreateHolder(Biomes.END_HIGHLANDS), biomeRegistry.getOrCreateHolder(Biomes.END_MIDLANDS), biomeRegistry.getOrCreateHolder(Biomes.SMALL_END_ISLANDS), biomeRegistry.getOrCreateHolder(Biomes.END_BARRENS));
@@ -87,12 +97,26 @@ public class TheEndBiomeSource extends BiomeSource {
float f = 100.0F - Mth.sqrt((long) i * (long) i + (long) j * (long) j) * 8.0F; // Paper - cast ints to long to avoid integer overflow
f = Mth.clamp(f, -100.0F, 80.0F);
+ NoiseCache cache = noiseCache.get().computeIfAbsent(simplexNoise, noiseKey -> new NoiseCache()); // Paper
for(int o = -12; o <= 12; ++o) {
for(int p = -12; p <= 12; ++p) {
long q = (long)(k + o);
long r = (long)(l + p);
- if (q * q + r * r > 4096L && simplexNoise.getValue((double)q, (double)r) < (double)-0.9F) {
- float g = (Mth.abs((float)q) * 3439.0F + Mth.abs((float)r) * 147.0F) % 13.0F + 9.0F;
+ // Paper start - Significantly improve end generation performance by using a noise cache
+ long key = net.minecraft.world.level.ChunkPos.asLong((int) q, (int) r);
+ int index = (int) it.unimi.dsi.fastutil.HashCommon.mix(key) & 8191;
+ float g = Float.MIN_VALUE;
+ if (cache.keys[index] == key) {
+ g = cache.values[index];
+ } else {
+ if (q * q + r * r > 4096L && simplexNoise.getValue((double)q, (double)r) < (double)-0.9F) {
+ g = (Mth.abs((float) q) * 3439.0F + Mth.abs((float) r) * 147.0F) % 13.0F + 9.0F;
+ }
+ cache.keys[index] = key;
+ cache.values[index] = g;
+ }
+ if (g != Float.MIN_VALUE) {
+ // Paper end
float h = (float)(m - o * 2);
float s = (float)(n - p * 2);
float t = 100.0F - Mth.sqrt(h * h + s * s) * g;

View File

@ -0,0 +1,63 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: SuperCoder7979 <25208576+SuperCoder7979@users.noreply.github.com>
Date: Tue, 3 Nov 2020 23:48:05 -0600
Subject: [PATCH] Significantly improve performance of the end generation
This patch implements a noise cache for the end which significantly reduces the computation time of generation. This results in about a 3x improvement.
Original code by SuperCoder7979 and Gegy in Lithium, licensed under LGPL-3.0 (Source: https://github.com/jellysquid3/lithium-fabric)
Co-authored-by: Gegy <gegy1000@gmail.com>
Co-authored-by: Dylan Xaldin <Puremin0rez515@gmail.com>
Co-authored-by: pop4959 <pop4959@gmail.com>
diff --git a/src/main/java/net/minecraft/world/level/levelgen/DensityFunctions.java b/src/main/java/net/minecraft/world/level/levelgen/DensityFunctions.java
index 6825feea42667a0f14c4c730e5f1ac970c654c56..1d00c019eb976de22be6e5e1f3632ca0c00d77ea 100644
--- a/src/main/java/net/minecraft/world/level/levelgen/DensityFunctions.java
+++ b/src/main/java/net/minecraft/world/level/levelgen/DensityFunctions.java
@@ -489,6 +489,16 @@ public final class DensityFunctions {
public static final KeyDispatchDataCodec<DensityFunctions.EndIslandDensityFunction> CODEC = KeyDispatchDataCodec.of(MapCodec.unit(new DensityFunctions.EndIslandDensityFunction(0L)));
private static final float ISLAND_THRESHOLD = -0.9F;
private final SimplexNoise islandNoise;
+ // Paper start
+ private static final class NoiseCache {
+ public long[] keys = new long[8192];
+ public float[] values = new float[8192];
+ public NoiseCache() {
+ java.util.Arrays.fill(keys, Long.MIN_VALUE);
+ }
+ }
+ private static final ThreadLocal<java.util.Map<SimplexNoise, NoiseCache>> noiseCache = ThreadLocal.withInitial(java.util.WeakHashMap::new);
+ // Paper end
public EndIslandDensityFunction(long seed) {
RandomSource randomSource = new LegacyRandomSource(seed);
@@ -504,12 +514,26 @@ public final class DensityFunctions {
float f = 100.0F - Mth.sqrt((long) i * (long) i + (long) j * (long) j) * 8.0F; // Paper - cast ints to long to avoid integer overflow
f = Mth.clamp(f, -100.0F, 80.0F);
+ NoiseCache cache = noiseCache.get().computeIfAbsent(simplexNoise, noiseKey -> new NoiseCache()); // Paper
for(int o = -12; o <= 12; ++o) {
for(int p = -12; p <= 12; ++p) {
long q = (long)(k + o);
long r = (long)(l + p);
- if (q * q + r * r > 4096L && simplexNoise.getValue((double)q, (double)r) < (double)-0.9F) {
- float g = (Mth.abs((float)q) * 3439.0F + Mth.abs((float)r) * 147.0F) % 13.0F + 9.0F;
+ // Paper start - Significantly improve end generation performance by using a noise cache
+ long key = net.minecraft.world.level.ChunkPos.asLong((int) q, (int) r);
+ int index = (int) it.unimi.dsi.fastutil.HashCommon.mix(key) & 8191;
+ float g = Float.MIN_VALUE;
+ if (cache.keys[index] == key) {
+ g = cache.values[index];
+ } else {
+ if (q * q + r * r > 4096L && simplexNoise.getValue((double)q, (double)r) < (double)-0.9F) {
+ g = (Mth.abs((float) q) * 3439.0F + Mth.abs((float) r) * 147.0F) % 13.0F + 9.0F;
+ }
+ cache.keys[index] = key;
+ cache.values[index] = g;
+ }
+ if (g != Float.MIN_VALUE) {
+ // Paper end
float h = (float)(m - o * 2);
float s = (float)(n - p * 2);
float t = 100.0F - Mth.sqrt(h * h + s * s) * g;

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Add OBSTRUCTED reason to BedEnterResult
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 396a66ccd90f8b5da42b585b50d2f0d5a80697b7..04923ca78b5866162612c5bc82e03c4ccd024c7f 100644
index b0aec2a6174048f38dd85360a4dda883ecff7111..46189c02e94af8520bf7e226f3924ba8952e72d6 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -263,6 +263,10 @@ public class CraftEventFactory {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Added ServerResourcesReloadedEvent
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 377c0011cd5c9d51360ff78e314d82259482ae35..4e2b59449f0916927fb4426a0e87b85ca17cbfcd 100644
index 0060211b3d85c07b44be3d3a534dcb8e35547d78..8460437b9210c8ae73795c65596ec35b491b18df 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1966,7 +1966,13 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

View File

@ -18,7 +18,7 @@ index 32c78828b0c85949832dc25843c881b8eecc63d6..06e7a8b8227260c002a88119544b99a1
this.interactResult = event.useItemInHand() == Event.Result.DENY;
this.interactPosition = blockposition.immutable();
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 99ce890f6014b66f7fd699cf72089fd3224fe30b..dadbb7d5295eea5097a2563775ae86b8a14d92f8 100644
index f89228c0c38c4acc299248e7d9639442eedca08b..a45ed570a7bf1becbc91c97c3890e99c0e5ebc0c 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -56,7 +56,9 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;

View File

@ -32,7 +32,7 @@ index 6c7105af36339514db02800e651cd0948d48bdaf..42b2f5c61e2bd07c3c86d889949c5f24
public boolean isWhiteListed(GameProfile profile) {
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index 772c7c34df1938efb4f97ef21ba39d75a5b8a1a5..482a6385d6d8072e2724054b91ea0347a648f8bc 100644
index 23a92393036fea7631d7610b12d4e72fa6657203..fd6f948adb975f09b07ad7692c6a716616600ccc 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -606,6 +606,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {

View File

@ -193,7 +193,7 @@ index 0000000000000000000000000000000000000000..6f39e343147803e15e7681c993b8797a
+public record RegistryKey<API extends Keyed, MINECRAFT>(Class<API> apiClass, ResourceKey<? extends Registry<MINECRAFT>> resourceKey) {
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 4e2b59449f0916927fb4426a0e87b85ca17cbfcd..2dbd4718b98f90842600ae4cde927b09d5fc738b 100644
index 8460437b9210c8ae73795c65596ec35b491b18df..18f050a80f9928bae3c1a0288f152907090644b7 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1998,6 +1998,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
@ -221,7 +221,7 @@ index 4192a6eff940bfe7823f100d4156f5c4d82d994c..e4855c7652b6904b402e38144664266d
/**
diff --git a/src/test/java/org/bukkit/support/AbstractTestingBase.java b/src/test/java/org/bukkit/support/AbstractTestingBase.java
index b58962026c739ed06fbe0f702cb2877fbfa7b2e4..b135f36a3b75f150781bd1e2d5852f18862a6a3a 100644
index 7de91b0b669664be3406b77a453d517604170404..747d150996ba56416e80293f616d8773878cceb5 100644
--- a/src/test/java/org/bukkit/support/AbstractTestingBase.java
+++ b/src/test/java/org/bukkit/support/AbstractTestingBase.java
@@ -38,6 +38,15 @@ public abstract class AbstractTestingBase {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] Allow adding items to BlockDropItemEvent
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index ad0a12f5d1b2179b31a307c0c5ca8478fbf43fc1..090c0cd38877ec06faa1e0ac43389a68c7153dac 100644
index 7893c10295abcd6ab2e3c4458c31f0b8914ba4c3..7570d5254b5807e967e7ab2560f091a9d601a876 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -396,13 +396,30 @@ public class CraftEventFactory {

View File

@ -255,7 +255,7 @@ index 0000000000000000000000000000000000000000..f39ae450e316255d315aeb362bf967ea
+
+}
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index b82e510939281efa3f32d21e8080adcf232285fc..3e496aa054ee707abcfd48e31dc0f62ae3371e9d 100644
index 49f481d34eec97c2bd4f0780e97ce2d41ed04b34..57924d8f2ddac1e7c0c151c4813a2a5ca17e58b8 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -1670,7 +1670,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

View File

@ -20,7 +20,7 @@ index ee5e59c37301d9a806e2f696d52d9d217b232833..bb5d22125b6cd4e60d2b7e2e00af158c
// Paper end
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 19aa748a38ab2d53cfe8a5f2ce95a285ae5fc957..288d6625c30e7d36c6c4ce372bccf3d42536be35 100644
index 41eaca0ef3d5d309fab7e7dddff0310d24c88966..5a84f867bd3b422706d03b75800adb9d7c445fc9 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -1132,9 +1132,15 @@ public final class CraftServer implements Server {

View File

@ -5,7 +5,7 @@ Subject: [PATCH] forced whitelist: use configurable kick message
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
index 3e496aa054ee707abcfd48e31dc0f62ae3371e9d..855a4a27cfa706432da6b75e1d80d1214917dab6 100644
index 57924d8f2ddac1e7c0c151c4813a2a5ca17e58b8..ff2a9dbacffdb1e4b790aedd61b82c7adf0831aa 100644
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
@@ -2080,7 +2080,7 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa

View File

@ -8,7 +8,7 @@ Paper.bypassHostCheck
Seriously, fix your firewalls. -.-
diff --git a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
index 9ece2ceac6c5095469b080f08bf7af8f7b31f003..142737266a2afcbbd70556615f56730d44e862f9 100644
index 750fef0f5b908b776a7306e54653eba497b7c50b..53833fdd748098b662d4420a254401c0d3982e56 100644
--- a/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerHandshakePacketListenerImpl.java
@@ -29,6 +29,7 @@ public class ServerHandshakePacketListenerImpl implements ServerHandshakePacketL

Some files were not shown because too many files have changed in this diff Show More