Merged threads and hydrology

- Bounded hydrology halo, performance-core pools
This commit is contained in:
Brian Neumann-Fopiano committed 2026-10-21 23:14:43 -04:00
commit f283d482a4
6 files changed
+47 -8

No files matched your search

@@ -26,7 +26,7 @@ public class MultiBurst extends MultiBurstSupport {
private final AtomicInteger parallelismBaseline = new AtomicInteger();
public MultiBurst() {
this("Iris");
this("Iris", Thread.MIN_PRIORITY, MultiBurstSupport::performanceProcessors);
}
public MultiBurst(String name) {
@@ -140,8 +140,15 @@ public class MultiBurst extends MultiBurstSupport {
static final class HydrologyBurst extends MultiBurst {
HydrologyBurst() {
super("Iris Hydrology", () -> Math.max(2,
IrisSettings.getThreadCount(IrisSettings.get().getConcurrency().getParallelism())));
super("Iris Hydrology", HydrologyBurst::plannerParallelism);
}
static int plannerParallelism() {
return plannerParallelism(MultiBurstSupport.performanceProcessors());
}
static int plannerParallelism(int performanceProcessors) {
return Math.max(4, performanceProcessors);
}
@Override
@@ -44,7 +44,7 @@ public final class HydrologyTileCache implements AutoCloseable {
private static final byte AROUND_EMPTY = 1;
private static final byte AROUND_PUBLISHED = 2;
private static final int MAXIMUM_PREGENERATION_TILES = 4096;
private static final int PREGENERATION_HALO_BLOCKS = 512;
private static final int PREGENERATION_HALO_BLOCKS = 256;
private static final HydrologyColumnSample[] NO_COLUMNS = new HydrologyColumnSample[CHUNK_COLUMN_COUNT];
private static final Cache<SharedTileKey, HydrologyTile> SHARED_TILES = Caffeine.newBuilder()
.maximumWeight(HydrologyCacheBudget.sharedStudioBytes())
@@ -24,6 +24,7 @@ import art.arcane.iris.generation.runtime.Engine;
import art.arcane.iris.platform.generation.PlatformChunkGenerator;
import art.arcane.iris.spi.IrisLogging;
import art.arcane.iris.generation.concurrent.MultiBurst;
import art.arcane.volmlib.util.parallel.MultiBurstSupport;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicInteger;
@@ -45,7 +46,7 @@ public final class PregenPerformanceProfile {
changed = true;
}
if (MultiBurst.burst.raiseParallelism(pregenBurstParallelism(Runtime.getRuntime().availableProcessors()))) {
if (MultiBurst.burst.raiseParallelism(pregenBurstParallelism(MultiBurstSupport.performanceProcessors()))) {
PARALLELISM_HOLDERS.incrementAndGet();
changed = true;
}
@@ -88,8 +89,8 @@ public final class PregenPerformanceProfile {
apply(generator == null ? null : generator.getEngine());
}
static int pregenBurstParallelism(int availableProcessors) {
return Math.max(4, availableProcessors * 2);
static int pregenBurstParallelism(int performanceProcessors) {
return Math.max(4, performanceProcessors * 2);
}
private static void prepareNoiseCacheInPlace(Engine engine) {
@@ -12,6 +12,7 @@ import java.util.concurrent.ForkJoinTask;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -60,6 +61,13 @@ public class HydrologyBurstTest {
assertTrue(pool.isTerminated());
}
@Test
public void plannerPoolFollowsThePerformanceCores() {
assertEquals(12, MultiBurst.HydrologyBurst.plannerParallelism(12));
assertEquals(4, MultiBurst.HydrologyBurst.plannerParallelism(1));
assertEquals(32, MultiBurst.HydrologyBurst.plannerParallelism(32));
}
@Test
public void closedHydrologyWorkersTerminateAndReopenCreatesANewPool() throws Exception {
IrisSettings previousSettings = IrisSettings.settings;
@@ -696,6 +696,29 @@ public class HydrologyTileCacheTest {
cache.close();
}
@Test
public void pregenSpeculationStaysWithinTheGenerationReachOfTheArea() {
HydrologyPlanner planner = mock(HydrologyPlanner.class);
HydrologyTile tile = mock(HydrologyTile.class);
HydrologyPlannerSettings settings = stalePrefetchSettings();
when(planner.settings()).thenReturn(settings);
ArrayList<HydrologyTileKey> planned = new ArrayList<>();
doAnswer(invocation -> {
planned.add(invocation.getArgument(0));
return tile;
}).when(planner).plan(any(HydrologyTileKey.class));
HydrologyTileCache cache = new HydrologyTileCache(planner, 128, Runnable::run);
try (HydrologyTileCache.PregenerationScope ignored = cache.preparePregeneration(
new HydrologyTileCache.PregenerationArea(1024, 1024, 736, 736, 1311, 1311))) {
assertEquals(prefetchRectangle(0, 1, 0, 1), new HashSet<>(planned));
cache.prepareChunkColumns(800, 800);
cache.prepareChunkColumns(1300, 1300);
assertEquals(prefetchRectangle(0, 1, 0, 1), new HashSet<>(planned));
assertEquals(4, planned.size());
}
cache.close();
}
@Test
public void pregenScopesRestoreStudioPrefetchAndIgnoreSupersededClose() {
HydrologyPlanner planner = mock(HydrologyPlanner.class);
@@ -99,7 +99,7 @@ public class PregenPerformanceProfileTest {
}
@Test
public void pregenerationWantsTwoBurstWorkersPerCore() {
public void pregenerationWantsTwoBurstWorkersPerPerformanceCore() {
assertEquals(32, PregenPerformanceProfile.pregenBurstParallelism(16));
assertEquals(4, PregenPerformanceProfile.pregenBurstParallelism(1));
}