Table of Contents

Class ChunkPool

Namespace
KeenEyes
Assembly
KeenEyes.Core.dll

Manages pooling and reuse of archetype chunks to reduce GC pressure.

public sealed class ChunkPool
Inheritance
ChunkPool
Inherited Members

Remarks

When an archetype chunk becomes empty, it can be returned to the pool for reuse. Chunks are pooled per-archetype (by ArchetypeId) since they have the same component layout.

The pool uses a LIFO (stack-based) strategy for better cache locality - recently returned chunks are more likely to still be in cache.

Constructors

ChunkPool(int)

Manages pooling and reuse of archetype chunks to reduce GC pressure.

public ChunkPool(int maxChunksPerArchetype = 64)

Parameters

maxChunksPerArchetype int

Maximum chunks to pool per archetype.

Remarks

When an archetype chunk becomes empty, it can be returned to the pool for reuse. Chunks are pooled per-archetype (by ArchetypeId) since they have the same component layout.

The pool uses a LIFO (stack-based) strategy for better cache locality - recently returned chunks are more likely to still be in cache.

Properties

PooledCount

Gets the number of chunks currently in the pool (across all archetypes).

public int PooledCount { get; }

Property Value

int

ReuseRate

Gets the pool reuse rate (returned / rented).

public double ReuseRate { get; }

Property Value

double

TotalCreated

Gets the total number of new chunks created (not from pool).

public long TotalCreated { get; }

Property Value

long

TotalDiscarded

Gets the total number of chunks discarded (pool was full).

public long TotalDiscarded { get; }

Property Value

long

TotalRented

Gets the total number of chunks rented from this pool.

public long TotalRented { get; }

Property Value

long

TotalReturned

Gets the total number of chunks returned to this pool.

public long TotalReturned { get; }

Property Value

long

Methods

Clear()

Clears all pooled chunks.

public void Clear()

ClearArchetype(ArchetypeId)

Clears all pooled chunks for the specified archetype.

public void ClearArchetype(ArchetypeId archetypeId)

Parameters

archetypeId ArchetypeId

The archetype identifier.

GetStats()

Gets statistics for this pool.

public ChunkPoolStats GetStats()

Returns

ChunkPoolStats

Rent(ArchetypeId, IEnumerable<ComponentInfo>, int)

Rents a chunk for the specified archetype.

public ArchetypeChunk Rent(ArchetypeId archetypeId, IEnumerable<ComponentInfo> componentInfos, int capacity = 128)

Parameters

archetypeId ArchetypeId

The archetype identifier.

componentInfos IEnumerable<ComponentInfo>

The component information (used if creating new chunk).

capacity int

The chunk capacity.

Returns

ArchetypeChunk

A chunk, either from the pool or newly created.

Remarks

Uses KeenEyes.ComponentInfo.CreateComponentArray factory delegates for AOT-compatible chunk creation without reflection.

Return(ArchetypeChunk)

Returns a chunk to the pool for reuse.

public bool Return(ArchetypeChunk chunk)

Parameters

chunk ArchetypeChunk

The chunk to return.

Returns

bool

True if the chunk was pooled, false if it was discarded.