utils: Implement Epoch-Based Reclamation (EBR) for Entity Management #10062
Open
pixelflinger wants to merge 2 commits into
Open
utils: Implement Epoch-Based Reclamation (EBR) for Entity Management #10062pixelflinger wants to merge 2 commits into
pixelflinger wants to merge 2 commits into
Conversation
dcdf2e5 to
63c0e78
Compare
63c0e78 to
2404250
Compare
poweifeng
approved these changes
Jun 4, 2026
2404250 to
c6bf38c
Compare
This allows to iterated a bitset while also clearing the visited bits.
c6bf38c to
87d07a0
Compare
This major architectural update introduces an Epoch-Based Reclamation (EBR) system to the EntityManager. It delays the recycling of destroyed Entity IDs until all active readers and component managers have advanced past the epoch in which the destruction occurred. The primary motivation for EBR is to decouple the lifecycle of the 32-bit Entity ID from the dense tracking structures. By guaranteeing that an entity's physical index is never safely recycled while any subsystem is still processing its destruction, component managers can safely transition to tracking entities purely by their raw index, dropping the generation count from their internal bitsets. This paves the way for drastically shrinking the memory footprint of structures like PagedArenaBitset (e.g., from 16KB down to 256B) in future updates. Key changes: - Implement `advanceEpoch()`, `registerWatermark()`, and `reclaimSafeEpochs()` in EntityManager to orchestrate the global timeline. - Introduce `catchupGarbage()` in SingleInstanceComponentManager to periodically query the central timeline for missed garbage and mark entities logically dead. - Amortize the physical destruction of component data into a `gc()` phase, safely holding zombie components in dense arrays until they can be cleaned up. - Prevent use-after-free ID collisions by keeping destroyed Entity indices in a purgatory epoch until the global safe threshold clears them. - Introduce exhaustive concurrent stress tests to ensure thread-safety of the timeline and bitset pools.
87d07a0 to
7c9ba80
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This major architectural update introduces an Epoch-Based Reclamation (EBR)
system to the EntityManager. It delays the recycling of destroyed Entity IDs
until all active readers and component managers have advanced past the epoch
in which the destruction occurred.
The primary motivation for EBR is to decouple the lifecycle of the 32-bit
Entity ID from the dense tracking structures. By guaranteeing that an entity's
physical index is never safely recycled while any subsystem is still processing
its destruction, component managers can safely transition to tracking entities
purely by their raw index, dropping the generation count from their internal
bitsets. This paves the way for drastically shrinking the memory footprint
of structures like PagedArenaBitset (e.g., from 16KB down to 256B) in future
updates.
Key changes:
advanceEpoch(),registerWatermark(), andreclaimSafeEpochs()in EntityManager to orchestrate the global timeline.
catchupGarbage()in SingleInstanceComponentManager toperiodically query the central timeline for missed garbage and mark
entities logically dead.
gc()phase,safely holding zombie components in dense arrays until they can be cleaned up.
in a purgatory epoch until the global safe threshold clears them.
the timeline and bitset pools.