minor speed improvements

This commit is contained in:
Julian Krings
2025-11-01 22:36:25 +01:00
parent ea5919def2
commit 4ca7ea3911
3 changed files with 13 additions and 7 deletions

View File

@@ -183,8 +183,13 @@ public class MantleWriter implements IObjectPlacer, AutoCloseable {
Iris.error("Mantle Writer Accessed chunk out of bounds" + cx + "," + cz);
return null;
}
MantleChunk chunk = cachedChunks.computeIfAbsent(Cache.key(cx, cz), k -> mantle.getChunk(cx, cz).use());
if (chunk == null) Iris.error("Mantle Writer Accessed " + cx + "," + cz + " and came up null (and yet within bounds!)");
final Long key = Cache.key(cx, cz);
MantleChunk chunk = cachedChunks.get(key);
if (chunk == null) {
chunk = mantle.getChunk(cx, cz).use();
var old = cachedChunks.put(key, chunk);
if (old != null) old.release();
}
return chunk;
}

View File

@@ -7,13 +7,12 @@ import com.volmit.iris.util.context.ChunkContext
import com.volmit.iris.util.documentation.ChunkCoordinates
import com.volmit.iris.util.mantle.Mantle
import com.volmit.iris.util.mantle.flag.MantleFlag
import com.volmit.iris.util.parallel.MultiBurst
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.util.concurrent.Executors
import kotlin.coroutines.EmptyCoroutineContext
interface MatterGenerator {
@@ -61,7 +60,7 @@ interface MatterGenerator {
}
companion object {
private val dispatcher = Executors.newVirtualThreadPerTaskExecutor().asCoroutineDispatcher()
private val dispatcher = MultiBurst.burst.dispatcher
private fun CoroutineScope.launch(block: suspend CoroutineScope.() -> Unit) =
launch(if (IrisSettings.get().generator.isUseMulticoreMantle) dispatcher else EmptyCoroutineContext, block = block)
}