mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 02:03:59 +00:00
Better caching
This commit is contained in:
parent
b59278601c
commit
a45d311339
@ -52,22 +52,18 @@ shadowJar
|
|||||||
{
|
{
|
||||||
minimize()
|
minimize()
|
||||||
dependencies {
|
dependencies {
|
||||||
include(dependency('com.github.ben-manes.caffeine:caffeine:2.8.5'))
|
|
||||||
include(dependency('org.zeroturnaround:zt-zip:1.14'))
|
include(dependency('org.zeroturnaround:zt-zip:1.14'))
|
||||||
include(dependency('io.papermc:paperlib:1.0.5'))
|
include(dependency('io.papermc:paperlib:1.0.5'))
|
||||||
|
include(dependency('com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compileOnly 'org.projectlombok:lombok:1.18.20'
|
compileOnly 'org.projectlombok:lombok:1.18.20'
|
||||||
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
annotationProcessor 'org.projectlombok:lombok:1.18.20'
|
||||||
|
|
||||||
// Shade
|
|
||||||
implementation 'com.github.ben-manes.caffeine:caffeine:3.0.2'
|
|
||||||
implementation 'org.zeroturnaround:zt-zip:1.14'
|
implementation 'org.zeroturnaround:zt-zip:1.14'
|
||||||
implementation 'io.papermc:paperlib:1.0.5'
|
implementation 'io.papermc:paperlib:1.0.5'
|
||||||
|
implementation 'com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:1.4.2'
|
||||||
// Provided
|
|
||||||
implementation 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'
|
implementation 'org.spigotmc:spigot-api:1.17-R0.1-SNAPSHOT'
|
||||||
implementation 'org.bukkit.craftbukkit:1.17:1.17'
|
implementation 'org.bukkit.craftbukkit:1.17:1.17'
|
||||||
implementation 'com.bergerkiller.bukkit:BKCommonLib:1.16.4-v2'
|
implementation 'com.bergerkiller.bukkit:BKCommonLib:1.16.4-v2'
|
||||||
|
@ -1,23 +1,28 @@
|
|||||||
package com.volmit.iris.scaffold.stream.utility;
|
package com.volmit.iris.scaffold.stream.utility;
|
||||||
|
|
||||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
|
||||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
import com.volmit.iris.Iris;
|
||||||
import com.volmit.iris.scaffold.cache.Cache;
|
import com.volmit.iris.scaffold.cache.Cache;
|
||||||
import com.volmit.iris.scaffold.stream.BasicStream;
|
import com.volmit.iris.scaffold.stream.BasicStream;
|
||||||
import com.volmit.iris.scaffold.stream.ProceduralStream;
|
import com.volmit.iris.scaffold.stream.ProceduralStream;
|
||||||
|
import com.volmit.iris.util.ChronoLatch;
|
||||||
|
import com.volmit.iris.util.Form;
|
||||||
|
|
||||||
public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStream<T>
|
public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStream<T>
|
||||||
{
|
{
|
||||||
private final ProceduralStream<T> stream;
|
private final ProceduralStream<T> stream;
|
||||||
private final LoadingCache<Long, T> cache;
|
private final ConcurrentLinkedHashMap<Long, T> cache;
|
||||||
|
private ChronoLatch cl = new ChronoLatch(1000);
|
||||||
|
|
||||||
public CachedStream2D(ProceduralStream<T> stream, int size)
|
public CachedStream2D(ProceduralStream<T> stream, int size)
|
||||||
{
|
{
|
||||||
super();
|
super();
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
cache = Caffeine.newBuilder()
|
cache = new ConcurrentLinkedHashMap.Builder<Long, T>()
|
||||||
.maximumSize(size)
|
.initialCapacity(size)
|
||||||
.build((b) -> stream.get(Cache.keyX(b), Cache.keyZ(b)));
|
.maximumWeightedCapacity(size)
|
||||||
|
.concurrencyLevel(32)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -35,7 +40,12 @@ public class CachedStream2D<T> extends BasicStream<T> implements ProceduralStrea
|
|||||||
@Override
|
@Override
|
||||||
public T get(double x, double z)
|
public T get(double x, double z)
|
||||||
{
|
{
|
||||||
return cache.get(Cache.key((int) x, (int) z));
|
if(cl.flip())
|
||||||
|
{
|
||||||
|
Iris.info("Cache: " + Form.f(cache.size()) + " / " + Form.f(cache.weightedSize()));
|
||||||
|
}
|
||||||
|
long ck = Cache.key((int) x, (int) z);
|
||||||
|
return cache.compute(ck, (k, v) -> v != null ? v : stream.get(Cache.keyX(ck), Cache.keyZ(ck)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user