N8: Stop the soak player holding old islands, and count live islands

The soak's client memory growth (17 to 20 MB, about five islands, in some
processes) came from SoakPlayer keeping a strong reference to the last world it
played on. It let go only when its client next asked it for a command on the
new world, so finished islands stayed alive across a match change. It now keeps
only the island's seed.

LiveCount counts live Simulations and SimGrounds, which are made on worker
threads too, so it is thread-safe. The soak clients log the counts, and the
soak report fails if, a minute into a match, any island is alive that isn't a
client's world or one being made. That makes a leak name itself instead of
showing up as bytes.

Refs #39

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-13 09:01:49 -05:00
co-authored by Claude Opus 5.5
parent 4993601616
commit 880e001fbb
8 changed files with 101 additions and 6 deletions
+22
View File
@@ -0,0 +1,22 @@
class_name LiveCount
extends RefCounted
## Counts live instances of a few heavy simulation classes, so leak checks (the soak)
## can tell how many islands a process still holds. Thread-safe: islands are made on
## worker threads.
static var _lock: Mutex = Mutex.new()
static var _counts: Dictionary = {}
static func add(kind: StringName, delta: int) -> void:
_lock.lock()
_counts[kind] = int(_counts.get(kind, 0)) + delta
_lock.unlock()
## How many of `kind` are alive now.
static func of(kind: StringName) -> int:
_lock.lock()
var count: int = int(_counts.get(kind, 0))
_lock.unlock()
return count
+1
View File
@@ -0,0 +1 @@
uid://cjyep4luipboh
+9
View File
@@ -33,6 +33,15 @@ var solids: Array[AABB] = []
var _index: Dictionary = {}
func _init() -> void:
LiveCount.add(&"SimGround", 1)
func _notification(what: int) -> void:
if what == NOTIFICATION_PREDELETE:
LiveCount.add(&"SimGround", -1)
## A flat world at `height`.
static func flat(height: float = 0.0) -> SimGround:
var ground: SimGround = SimGround.new()
+6
View File
@@ -67,6 +67,7 @@ var _players: Array[int] = []
## Generates the island from the seed, unless `world` is given. Tests that don't care
## about terrain pass `SimGround.flat()` to skip worldgen.
func _init(match_seed: int, world: SimGround = null) -> void:
LiveCount.add(&"Simulation", 1)
rng = SimRng.new(match_seed)
if world == null:
island = Island.generate(match_seed)
@@ -402,3 +403,8 @@ func state_hash() -> String:
hasher.start(HashingContext.HASH_SHA256)
hasher.update(buffer.data_array)
return hasher.finish().hex_encode()
func _notification(what: int) -> void:
if what == NOTIFICATION_PREDELETE:
LiveCount.add(&"Simulation", -1)