Repository navigation
Conversation
…m; bump 0.10.37 Co-Authored-By: OpenCode <noreply@opencode.ai>
Entity ids carry an 8-bit generation (top byte); local index is 22 bits. Freed slots are reused with an advanced generation, so stale ids fail locate without unbounded table growth. Persistence stores the generation in the top byte of each entity-location slot; files without it load as generation 0. Co-Authored-By: OpenCode <noreply@opencode.ai>
This branch has not been deployed
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.
Problem
createLocalIndexEntityLocationTablereused a deleted slot immediately (LIFO free list) and returned the same entity id, with nothing to tell the old and new occupant apart. Any code holding anEntityacross a delete silently resolved to a different row. Coediting hit this three times: a delta deletes A then inserts B, B gets A's id, and a stale GUID→entity map entry points at B.Design
Entity ids carry a generation, in the style of
@adobe/ecs, packed into the existing 32-bitEntity:locate/read/deletecompare the id's generation to the slot's, so an id from before the free no longer resolves. Slots are still reused through the free list, so table memory is bounded by the peak live count.Entity.none(-1) is still never issued: the allocator caps local indices below the reserved maximum.Entity.toEntitygains an optionalgeneration;Entity.generationOfis new. The layout is still defined only inpersistence-sharing.ts.Undo/redo and reconciling replay
Generations change two behaviours that previously worked by accident of LIFO reuse:
TransactionInsertOperationrecords an optionalentity; replay restores it at its own generation viaEntityLocationTable.restore(returnsfalse, and falls back to a fresh insert, if that slot is live in the replay base).rewind, which does not advance the generation.Persistence compatibility
The generation is stored in the top byte of the first word of each 8-byte entity-location slot (low 24 bits stay
archetypeId + 1). A deleted slot is written as an empty entry carrying the generation its next occupant gets.ECS_SNAPSHOT_VERSIONis unchanged and a core snapshot withoutgenerationsloads every slot at generation 0.Tests
generationsloads at generation 0; rebuilt snapshot that exactly fills its capacity;rewind;restore(free list unlinking, past the high-water mark, refuses a live slot).none.entity-generation-persistence.test.ts, node + chromium): a reused slot keeps its generation, a deleted slot keeps its next generation, and an entity reference to a generation-1 entity resolves after reload, each from a checkpoint and from journal replay only; generation-0 entries are written in the pre-generation byte format; a pre-generation file loads at generation 0. The six generation tests fail without the persistence change; the two compatibility tests pass either way.Performance
Measured on the compiled output (native ESM), table-level, against
main's table:Each slot adds one byte of generation storage.
Verification
pnpm run lint,pnpm run typecheck,pnpm run buildandpnpm run test(every workspace package) all pass.