mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-12 03:24:14 +00:00
Spread native volume cache keys
- Mix chunk keys so origin and query caches stop treeifying buckets
This commit is contained in:
@@ -8,6 +8,7 @@ import art.arcane.volmlib.nativelib.terrain.structure.NativeStructureVolume;
|
||||
import art.arcane.iris.generation.runtime.IrisEngine;
|
||||
import art.arcane.iris.generation.runtime.Engine;
|
||||
import art.arcane.iris.world.history.GenerationHistoryRuntimeRouter;
|
||||
import art.arcane.volmlib.util.cache.CacheKey;
|
||||
import art.arcane.volmlib.util.collection.KList;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -313,7 +314,15 @@ public final class NativeStructureVolumeIndex {
|
||||
};
|
||||
}
|
||||
|
||||
static int runtimeChunkHash(int runtimeId, long chunkKey) {
|
||||
return Long.hashCode(CacheKey.mix(chunkKey)) * 31 + runtimeId;
|
||||
}
|
||||
|
||||
private record RuntimeChunkKey(int runtimeId, long chunkKey) {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return runtimeChunkHash(runtimeId, chunkKey);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package art.arcane.iris.structure.nativegen;
|
||||
|
||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class NativeStructureVolumeIndexKeyTest {
|
||||
@Test
|
||||
public void neighbouringChunkKeysSpreadAcrossHashBuckets() {
|
||||
IntOpenHashSet buckets = new IntOpenHashSet();
|
||||
int keys = 0;
|
||||
for (int chunkX = -64; chunkX < 64; chunkX++) {
|
||||
for (int chunkZ = -64; chunkZ < 64; chunkZ++) {
|
||||
long chunkKey = ((long) chunkX << 32) ^ (chunkZ & 0xffffffffL);
|
||||
int hash = NativeStructureVolumeIndex.runtimeChunkHash(7, chunkKey);
|
||||
buckets.add((hash ^ (hash >>> 16)) & ((1 << 15) - 1));
|
||||
keys++;
|
||||
}
|
||||
}
|
||||
assertTrue("buckets=" + buckets.size(), buckets.size() > keys / 2);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user