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)
@@ -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 {