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 lock = ReentrantLock()
|
||||
private val level2cache = Caffeine.newBuilder()
|
||||
.scheduler(Scheduler.systemScheduler())
|
||||
.executor(Util.backgroundExecutor())
|
||||
.expireAfterAccess(Duration.ofMinutes(10))
|
||||
.weakKeys()
|
||||
.build<WorldGenLevel, Cache<ChunkPos, GeneratedChunk>>()
|
||||
|
||||
private fun getCache(level: WorldGenLevel): Cache<ChunkPos, GeneratedChunk> {
|
||||
return lock.withLock {
|
||||
level2cache.computeIfAbsent(level) {
|
||||
return level2cache.get(level) {
|
||||
Caffeine.newBuilder()
|
||||
.scheduler(Scheduler.systemScheduler())
|
||||
.executor(Util.backgroundExecutor())
|
||||
@ -81,7 +84,6 @@ class EnormousPlacement(
|
||||
.build()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeChunk(context: PlacementContext, pos: ChunkPos): GeneratedChunk {
|
||||
val bytes = FastByteArrayOutputStream()
|
||||
|
Loading…
Reference in New Issue
Block a user