From be6f637d9bf95c62b60a8c70e9457fd2ad30e143 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 6 May 2024 14:43:45 +0700 Subject: [PATCH] Set generation caches to expireafterwrite, to reduce cpu pressure --- .../ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt | 2 +- .../kstarbound/world/terrain/IslandSurfaceTerrainSelector.kt | 4 ++-- .../kstarbound/world/terrain/KarstCaveTerrainSelector.kt | 4 ++-- .../kstarbound/world/terrain/WormCaveTerrainSelector.kt | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt index e3c6653b..816c5cf2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/defs/world/WorldTemplate.kt @@ -302,7 +302,7 @@ class WorldTemplate(val geometry: WorldGeometry) { Caffeine.newBuilder() .maximumSize(50_000L) // plentiful of space, and allows for high hit ratio (around 79%) in most situations // downside is memory consumption, but why should it matter when we save 80% of cpu time? - .expireAfterAccess(Duration.ofSeconds(20)) + .expireAfterWrite(Duration.ofSeconds(30)) .executor(Starbound.EXECUTOR) .scheduler(Starbound) // .recordStats() diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/IslandSurfaceTerrainSelector.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/IslandSurfaceTerrainSelector.kt index c8967e54..1048e2f1 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/IslandSurfaceTerrainSelector.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/IslandSurfaceTerrainSelector.kt @@ -91,8 +91,8 @@ class IslandSurfaceTerrainSelector(data: Data, parameters: TerrainSelectorParame private val cache = Caffeine.newBuilder() .maximumSize(512L) - //.executor(Starbound.EXECUTOR) - //.scheduler(Starbound) + .executor(Starbound.EXECUTOR) + .scheduler(Starbound) .build(::compute) override fun get(x: Int, y: Int): Double { diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/KarstCaveTerrainSelector.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/KarstCaveTerrainSelector.kt index 81fbb5b4..3e2810e2 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/KarstCaveTerrainSelector.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/KarstCaveTerrainSelector.kt @@ -59,7 +59,7 @@ class KarstCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters private val layers = Caffeine.newBuilder() .maximumSize(2048L) .softValues() - .expireAfterAccess(Duration.ofMinutes(1)) + .expireAfterWrite(Duration.ofMinutes(1)) .scheduler(Starbound) .executor(Starbound.EXECUTOR) .build(::Layer) @@ -128,7 +128,7 @@ class KarstCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters private val sectors = Caffeine.newBuilder() .maximumSize(512L) .softValues() - .expireAfterAccess(Duration.ofMinutes(1)) + .expireAfterWrite(Duration.ofMinutes(1)) .scheduler(Starbound) .executor(Starbound.EXECUTOR) .build(::Sector) diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/WormCaveTerrainSelector.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/WormCaveTerrainSelector.kt index 6c4d90b4..e557432e 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/WormCaveTerrainSelector.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/world/terrain/WormCaveTerrainSelector.kt @@ -182,7 +182,7 @@ class WormCaveTerrainSelector(data: Data, parameters: TerrainSelectorParameters) private val sectors = Caffeine.newBuilder() .maximumSize(512L) .softValues() - .expireAfterAccess(Duration.ofMinutes(1)) + .expireAfterWrite(Duration.ofMinutes(1)) .scheduler(Starbound) .executor(Starbound.EXECUTOR) .build(::Sector)