9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-19 15:09:18 +00:00

potential optimization for the noise cache

This commit is contained in:
Julian Krings
2025-11-21 16:21:54 +01:00
parent 0b0797f876
commit 6373dbb1b8
3 changed files with 20 additions and 2 deletions

View File

@@ -234,7 +234,7 @@ public class IrisToolbelt {
} }
public static void retainMantleDataForSlice(String className) { public static void retainMantleDataForSlice(String className) {
toolbeltConfiguration.put("retain.mantle." + className, true); toolbeltConfiguration.put("retain.mantle." + className, Boolean.TRUE);
} }
public static boolean isRetainingMantleDataForSlice(String className) { public static boolean isRetainingMantleDataForSlice(String className) {

View File

@@ -2,22 +2,36 @@ package com.volmit.iris.util.cache;
import com.volmit.iris.util.function.Function2; import com.volmit.iris.util.function.Function2;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
public class ChunkCache2D<T> { public class ChunkCache2D<T> {
private static final boolean FAST = Boolean.getBoolean("iris.cache.fast"); private static final boolean FAST = Boolean.getBoolean("iris.cache.fast");
private static final boolean DYNAMIC = Boolean.getBoolean("iris.cache.dynamic");
private static final VarHandle AA = MethodHandles.arrayElementVarHandle(Entry[].class);
private final Entry<T>[] cache; private final Entry<T>[] cache;
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
public ChunkCache2D() { public ChunkCache2D() {
this.cache = new Entry[256]; this.cache = new Entry[256];
if (DYNAMIC) return;
for (int i = 0; i < cache.length; i++) { for (int i = 0; i < cache.length; i++) {
cache[i] = FAST ? new FastEntry<>() : new Entry<>(); cache[i] = FAST ? new FastEntry<>() : new Entry<>();
} }
} }
@SuppressWarnings({"unchecked"})
public T get(int x, int z, Function2<Integer, Integer, T> resolver) { public T get(int x, int z, Function2<Integer, Integer, T> resolver) {
int key = ((z & 15) * 16) + (x & 15); int key = ((z & 15) * 16) + (x & 15);
return cache[key].compute(x, z, resolver); var entry = cache[key];
if (entry == null) {
entry = FAST ? new FastEntry<>() : new Entry<>();
if (!AA.compareAndSet(cache, key, null, entry)) {
entry = (Entry<T>) AA.getVolatile(cache, key);
}
}
return entry.compute(x, z, resolver);
} }
private static class Entry<T> { private static class Entry<T> {

View File

@@ -25,4 +25,8 @@ public class WorldCache2D<T> {
public long getSize() { public long getSize() {
return chunks.size() * 256L; return chunks.size() * 256L;
} }
public long getMaxSize() {
return chunks.capacity() * 256L;
}
} }