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
maxChunksPerArchetypeintMaximum 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
ReuseRate
Gets the pool reuse rate (returned / rented).
public double ReuseRate { get; }
Property Value
TotalCreated
Gets the total number of new chunks created (not from pool).
public long TotalCreated { get; }
Property Value
TotalDiscarded
Gets the total number of chunks discarded (pool was full).
public long TotalDiscarded { get; }
Property Value
TotalRented
Gets the total number of chunks rented from this pool.
public long TotalRented { get; }
Property Value
TotalReturned
Gets the total number of chunks returned to this pool.
public long TotalReturned { get; }
Property Value
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
archetypeIdArchetypeIdThe archetype identifier.
GetStats()
Gets statistics for this pool.
public ChunkPoolStats GetStats()
Returns
Rent(ArchetypeId, IEnumerable<ComponentInfo>, int)
Rents a chunk for the specified archetype.
public ArchetypeChunk Rent(ArchetypeId archetypeId, IEnumerable<ComponentInfo> componentInfos, int capacity = 128)
Parameters
archetypeIdArchetypeIdThe archetype identifier.
componentInfosIEnumerable<ComponentInfo>The component information (used if creating new chunk).
capacityintThe 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
chunkArchetypeChunkThe chunk to return.
Returns
- bool
True if the chunk was pooled, false if it was discarded.