Use nested caches for enormous placements instead of weak hash map
Should recycle memory better
This commit is contained in:
parent
cc456958e1
commit
44b0bcd776
@ -66,12 +66,15 @@ class EnormousPlacement(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val level2cache = WeakHashMap<WorldGenLevel, Cache<ChunkPos, GeneratedChunk>>()
|
private val level2cache = Caffeine.newBuilder()
|
||||||
private val lock = ReentrantLock()
|
.scheduler(Scheduler.systemScheduler())
|
||||||
|
.executor(Util.backgroundExecutor())
|
||||||
|
.expireAfterAccess(Duration.ofMinutes(10))
|
||||||
|
.weakKeys()
|
||||||
|
.build<WorldGenLevel, Cache<ChunkPos, GeneratedChunk>>()
|
||||||
|
|
||||||
private fun getCache(level: WorldGenLevel): Cache<ChunkPos, GeneratedChunk> {
|
private fun getCache(level: WorldGenLevel): Cache<ChunkPos, GeneratedChunk> {
|
||||||
return lock.withLock {
|
return level2cache.get(level) {
|
||||||
level2cache.computeIfAbsent(level) {
|
|
||||||
Caffeine.newBuilder()
|
Caffeine.newBuilder()
|
||||||
.scheduler(Scheduler.systemScheduler())
|
.scheduler(Scheduler.systemScheduler())
|
||||||
.executor(Util.backgroundExecutor())
|
.executor(Util.backgroundExecutor())
|
||||||
@ -81,7 +84,6 @@ class EnormousPlacement(
|
|||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun computeChunk(context: PlacementContext, pos: ChunkPos): GeneratedChunk {
|
private fun computeChunk(context: PlacementContext, pos: ChunkPos): GeneratedChunk {
|
||||||
val bytes = FastByteArrayOutputStream()
|
val bytes = FastByteArrayOutputStream()
|
||||||
|
Loading…
Reference in New Issue
Block a user