Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World rewrite #67

Closed
wants to merge 35 commits into from
Closed

World rewrite #67

wants to merge 35 commits into from

Conversation

Ukendio
Copy link
Member

@Ukendio Ukendio commented Apr 28, 2024

This is currently a draft but it rewrites the registry of Matter in order to improve the performance of a couple key operations such as queries, random access and moving of entities.

The center piece of the optimizations is the component index (refer to section 4. Implementation in my paper on ECS). It allows fast iteration over a pre-matched list of compatible archetypes for a corresponding base component. This is helpful in populating the uncached query in a less naive way than how Matter currently does it that would go through every archetype and checking compatibility ad-hoc which was non trivial when you had high fragmentation of archetypes.

The archetypes in this rewrite are implemented in a tabular design that leverages SoA access pattern of entities as opposed to Matter's interleaved layout. This enables better performance for column major operations like queries where the indexing is terse for each group of entities.

The moving of entities is also much faster because it can find an adjacent archetype in O(1) thanks to the archetype graph, (refer to section 3. Theory), it does not need any recomputations of hashing an entity's archetype. The draft currently does not have any function to commit a bulk operation of adding/removing components but this will be addressed in the future.

Separately the intent of this rewrite is to move the cost of preventing iterator invalidation from the iterator to other things that could be in the form of "stages" or "command buffers".

As noted in issue #52, the interleaved layout and the dirty/pristine storage bookkeeping make Matter's queries non-trivial to iterate. This is evident from how jecs has already implemented these changes and performs much faster, demonstrating that there is significant room for improvement.

Checklist

  • Archetype
    • function for transitioning archetype for a corresponding entity
    • archetype graph for caching pointers to adjacent archetypes
  • EntityIndex (sparse set)
    • entity liveliness check
    • generations
  • ComponentIndex
  • Deferring entity operations
  • queryChanged
  • Benchmarks
  • Archetype Recycling
    • creation
    • deletion
  • Entity deletion
    • clear all components
    • cascade deletion of entity to dependants

@memorycode memorycode self-assigned this May 20, 2024
@LastTalon LastTalon linked an issue Jun 12, 2024 that may be closed by this pull request
@LastTalon LastTalon added this to the World Rewrite milestone Jul 15, 2024
@Ukendio Ukendio closed this Oct 21, 2024
@Ukendio
Copy link
Member Author

Ukendio commented Oct 21, 2024

F in chat

@LastTalon
Copy link
Member

F in chat

Did you write everything you were planning on for this as an issue? I'd still like to get it done, but just not as one giant change.

@LastTalon LastTalon deleted the world-rewrite branch November 15, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Matter's archetype storage
3 participants