Memory Pool for Entities #117
Labels
No labels
Alpha Release Requirement
Bugfix
Demo Target
Documentation
Major Feature
Minor Feature
priority:tier1-active
priority:tier2-foundation
priority:tier3-future
priority:tier4-deferred
Refactoring & Cleanup
system:animation
system:documentation
system:grid
system:input
system:performance
system:procgen
system:python-binding
system:rendering
system:ui-hierarchy
Tiny Feature
workflow:blocked
workflow:needs-benchmark
workflow:needs-documentation
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
john/McRogueFace#117
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Implement memory pooling for entity allocation/deallocation.
Definition of Done:
Benchmark Results (commit
fcc0376)Added
tests/benchmarks/entity_scale_benchmark.pyto establish baseline metrics.Current Performance (2,000 entities on 100×100 grid)
Key Finding: EntityCollection Overhead
Direct C++ iteration (via
list(grid.entities)then loop): 0.23msEntityCollection iteration (via
for e in grid.entities): 13.6msThe 60× slowdown comes from Python wrapper object creation on each access. Each call to
__next__in the iterator:PyUIEntityObjectshared_ptrProjected Gains with Memory Pool
Mechanism: Pre-allocate entity memory in contiguous blocks. Reduces malloc overhead and improves CPU cache utilization.
Additional Finding
The EntityCollection overhead suggests a secondary optimization: batch access APIs that return data without per-entity Python object creation. For example:
grid.entity_positions()→ numpy array of (x, y) pairsgrid.entities_in_rect(x, y, w, h)→ filtered listThis would complement the memory pool by reducing Python/C++ boundary crossings.
Current Performance Assessment
After implementing #159 (iterator fix) and #115 (SpatialHash), the benchmark shows:
Analysis
The entity creation rate of 80k/sec is likely sufficient for roguelike games where:
Bottleneck Investigation
The entity creation overhead comes from:
std::make_shared<UIEntity>()- heap allocationtp_allocA C++ memory pool would help with #1 but not #2-4 which dominate.
Recommendation
Given the significant gains from #115 (104× speedup on N×N) and the acceptable creation rate, I recommend:
grid.create_entities(positions)) for level generation if needed