Skip to main content

PoolStats

Kindclass
Packagedebug
Full namedebug.PoolStats
Sourcesource/debug/PoolStats.hx

Allocation accounting for the pooled gameplay objects of play.PlayState.

Notes, sustains, splashes, rating popups and cross fades are all served by FlxTypedGroup.recycle() pools, but a pool that silently stops being hit (a destroy() where a kill() was meant, a remove(…, true) on the hot path, a member spliced out of the group) shows up as garbage-collector stutter long before it shows up as a bug. Issue #88: HTML5 has no readable managed heap, so debug.FrameProfiler.queryHeapUsedBytes() reports -1.0 there and the profiler CSV has nothing to say about the note path on web. These counters are that missing signal: they are platform independent, and every read is a plain Int.

Semantics, per pool slot:

  • createdCount — a sprite had to be constructed (pool miss / pool growth).
  • reusedCount — a dead sprite was revived from the pool (pool hit).
  • releasedCount — a sprite left the live set, either kill()ed back into the pool or destroyed by a destructive path (song reset, seek, KillNotes).
  • liveCount — spawnCount - releasedCount, i.e. sprites currently out of the pool. A song that reuses well keeps this bounded at the concurrency peak and keeps createdCount flat after the first few seconds.

A steady state of createdCount == 0 growth with a climbing reusedCount is the property the pooling work is meant to guarantee; the counters make it observable in a debug build and assertable in tests/haxe/PoolStatsSpec.hx.

Public fields​

NameTypeStaticDefaultNotes
NOTEIntyes0final · Parent note sprites, pooled by PlayState.notes.
SUSTAINIntyes1final · Sustain (hold) pieces, pooled by PlayState.sustainNotes.
NOTE_SPLASHIntyes2final · Hit splashes, pooled by PlayState.grpNoteSplashes.
HOLD_SPLASHIntyes3final · Hold splashes, pooled by PlayState.grpHoldSplashes.
POPUPIntyes4final · Rating/combo popups, pooled by PlayState.popUpGroup.
CROSS_FADEIntyes5final · Opponent cross fade ghosts, pooled by the grp*CrossFade groups.
POOL_COUNTIntyes6final · Number of tracked pool slots.

Public methods​

spawn​

static inline function spawn(pool:Int, fromPool:Bool):Void

Records one spawn served by a pool.

@param pool one of the slot constants of this class. @param fromPool true when the sprite was revived from the pool, false when it had to be constructed. Callers derive this from the group size: recycle() grows the group only on a miss.

ParameterTypeDefault
poolInt—
fromPoolBool—

View source

release​

static inline function release(pool:Int):Void

Records one sprite leaving the live set (killed back into the pool or destroyed by a destructive path).

@param pool one of the slot constants of this class.

ParameterTypeDefault
poolInt—

View source

reset​

static function reset():Void

Clears every counter; called when a song starts so numbers are per play.

View source

isValid​

static inline function isValid(pool:Int):Bool

Whether pool is a tracked slot.

ParameterTypeDefault
poolInt—

View source

name​

static function name(pool:Int):String

Debug name of a pool slot ("unknown" when out of range).

ParameterTypeDefault
poolInt—

View source

createdCount​

static inline function createdCount(pool:Int):Int

Sprites that had to be constructed for this pool.

ParameterTypeDefault
poolInt—

View source

reusedCount​

static inline function reusedCount(pool:Int):Int

Sprites this pool served by reviving a dead member.

ParameterTypeDefault
poolInt—

View source

releasedCount​

static inline function releasedCount(pool:Int):Int

Sprites that left the live set for this pool.

ParameterTypeDefault
poolInt—

View source

spawnCount​

static inline function spawnCount(pool:Int):Int

Total spawns served by this pool, from the pool or freshly built.

ParameterTypeDefault
poolInt—

View source

liveCount​

static inline function liveCount(pool:Int):Int

Sprites currently out of the pool, never negative. Counts spawns rather than constructions: a pooled sprite is constructed once but retired and revived many times, so only the spawn/release difference tracks live occupancy.

ParameterTypeDefault
poolInt—

View source

reuseRate​

static function reuseRate(pool:Int):Float

Share of spawns served from the pool, 0..1 (0 when nothing spawned yet).

ParameterTypeDefault
poolInt—

View source

totalCreated​

static function totalCreated():Int

Sprites constructed across every tracked pool.

View source

totalReused​

static function totalReused():Int

Spawns served from a pool across every tracked pool.

View source

totalSpawned​

static function totalSpawned():Int

Every spawn served across every tracked pool.

View source

totalReuseRate​

static function totalReuseRate():Float

Share of all spawns served from a pool, 0..1.

View source

summary​

static function summary():String

One line per pool that actually spawned something, e.g. note 12/140 (91%) sustain 8/60 (86%). Built at most once a second by the FPS overlay, so the concatenations are not on a hot path.

View source

Internals​

Private / internal members
FieldTypeStatic
namesArray<String>yes
createdArray<Int>yes
reusedArray<Int>yes
releasedArray<Int>yes