Reuse cave biome cache

- Carve scratch keeps one cave biome cache per thread, cleared per chunk
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-21 19:29:37 -04:00
1 parent 7282a46a26
commit 6ebb700be0
3 files changed
+7 -1

No files matched your search

@@ -102,9 +102,9 @@ public class IrisCarveModifier extends EngineAssignedModifier<NativeBlockState>
PrecisionStopwatch caveStopwatch = PrecisionStopwatch.start(); PrecisionStopwatch caveStopwatch = PrecisionStopwatch.start();
Mantle<Matter> mantle = getEngine().getMantle().getMantle(); Mantle<Matter> mantle = getEngine().getMantle().getMantle();
CaveInputs resolverState = new CaveInputs(getEngine()); CaveInputs resolverState = new CaveInputs(getEngine());
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache = new Long2ObjectOpenHashMap<>(2048);
IrisCarveScratch scratch = SCRATCH.get(); IrisCarveScratch scratch = SCRATCH.get();
scratch.reset(); scratch.reset();
Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache = scratch.caveBiomeCache;
CarveWallBuffer walls = scratch.walls; CarveWallBuffer walls = scratch.walls;
CarveColumnMask[] columnMasks = scratch.columnMasks; CarveColumnMask[] columnMasks = scratch.columnMasks;
CarveColumnMask[] boundaryMasks = scratch.boundaryMasks; CarveColumnMask[] boundaryMasks = scratch.boundaryMasks;
@@ -21,6 +21,7 @@ package art.arcane.iris.generation.stage;
import art.arcane.iris.generation.biome.IrisBiome; import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.volmlib.util.matter.MatterCavern; import art.arcane.volmlib.util.matter.MatterCavern;
import art.arcane.volmlib.util.math.PowerOfTwoCoordinates; import art.arcane.volmlib.util.math.PowerOfTwoCoordinates;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
@@ -32,6 +33,7 @@ final class IrisCarveScratch {
final int[] surfaceHeights = new int[256]; final int[] surfaceHeights = new int[256];
final CarveWallBuffer walls = new CarveWallBuffer(512); final CarveWallBuffer walls = new CarveWallBuffer(512);
final Map<String, IrisBiome> customBiomeCache = new HashMap<>(); final Map<String, IrisBiome> customBiomeCache = new HashMap<>();
final Long2ObjectOpenHashMap<IrisBiome> caveBiomeCache = new Long2ObjectOpenHashMap<>(4096);
int[] upperSurfaceHeights; int[] upperSurfaceHeights;
boolean customCaveBiomePresent; boolean customCaveBiomePresent;
@@ -56,6 +58,7 @@ final class IrisCarveScratch {
} }
walls.clear(); walls.clear();
customBiomeCache.clear(); customBiomeCache.clear();
caveBiomeCache.clear();
customCaveBiomePresent = false; customCaveBiomePresent = false;
} }
} }
@@ -1,5 +1,6 @@
package art.arcane.iris.generation.stage; package art.arcane.iris.generation.stage;
import art.arcane.iris.generation.biome.IrisBiome;
import art.arcane.volmlib.util.matter.MatterCavern; import art.arcane.volmlib.util.matter.MatterCavern;
import org.junit.Test; import org.junit.Test;
@@ -49,6 +50,7 @@ public class IrisCarveScratchTest {
scratch.boundaryMasks[0].add(13); scratch.boundaryMasks[0].add(13);
scratch.walls.put(1, 12, 2, cavern); scratch.walls.put(1, 12, 2, cavern);
scratch.customBiomeCache.put("cave", null); scratch.customBiomeCache.put("cave", null);
scratch.caveBiomeCache.put(42L, new IrisBiome());
scratch.customCaveBiomePresent = true; scratch.customCaveBiomePresent = true;
scratch.reset(); scratch.reset();
@@ -56,6 +58,7 @@ public class IrisCarveScratchTest {
assertTrue(scratch.columnMasks[0].isEmpty()); assertTrue(scratch.columnMasks[0].isEmpty());
assertTrue(scratch.boundaryMasks[0].isEmpty()); assertTrue(scratch.boundaryMasks[0].isEmpty());
assertTrue(scratch.customBiomeCache.isEmpty()); assertTrue(scratch.customBiomeCache.isEmpty());
assertTrue(scratch.caveBiomeCache.isEmpty());
assertFalse(scratch.customCaveBiomePresent); assertFalse(scratch.customCaveBiomePresent);
int[] wallCount = new int[1]; int[] wallCount = new int[1];
scratch.walls.forEach((x, y, z, value) -> wallCount[0]++); scratch.walls.forEach((x, y, z, value) -> wallCount[0]++);