Skip to content

Conversation

JoNax97
Copy link
Contributor

@JoNax97 JoNax97 commented Aug 25, 2025

Adds the ability to mark entities as changed on a per-component basis. This can be done manually by calling entity.MarkChanged<MyComponentType>() or (coming soon) automatically when a query potentially modifies it.

It works by storing a BitSet for each entity inside each chunk.

It's behind a compile-time flag and even when enabled, it should have minimal cpu and memory overhead when unused.

Remaining work:

  • Add a single chunk-level flag to speed up changed checking
  • Add change-filtering support to world query methods
  • Add change-filtering support to generated query methods
  • Automatically mark chunks as changed when queries write to a component
  • Preserve changed status when moving entities between chunks
  • Add tests
  • Add performance benchmarks

@JoNax97
Copy link
Contributor Author

JoNax97 commented Aug 26, 2025

@genaray I'd like to hear your opinion on the implementation, to know if I'm going in the right direction.

@genaray
Copy link
Owner

genaray commented Sep 2, 2025

@JoNax97
Thanks!
Looks fine to me, however i wonder whats the Performance Impact will be If every entity hast its own bitset stored in the chunk. Wondering If there better ways of doing that 🤔

@JoNax97
Copy link
Contributor Author

JoNax97 commented Sep 3, 2025

I considered making the change tracker a component, but in order to avoid unexpected structural changes, the user would need to opt-in to the feature at entity creation time. What's your view on that?

Additionally, it would make it less performant to check for changed components in queries. The current approach wil allow for skipping whole chunks with a single boolean check

@genaray
Copy link
Owner

genaray commented Sep 5, 2025

I considered making the change tracker a component, but in order to avoid unexpected structural changes, the user would need to opt-in to the feature at entity creation time. What's your view on that?

Additionally, it would make it less performant to check for changed components in queries. The current approach wil allow for skipping whole chunks with a single boolean check

True, I assume this is the best way of doing it so far. I guess we could merge it then, tests are missing tho :)

@genaray
Copy link
Owner

genaray commented Sep 8, 2025

The pipeline fails for some reason, not sure why atm .

@JoNax97
Copy link
Contributor Author

JoNax97 commented Sep 9, 2025

Updated the PR with most of the support for filtering non-changed entities in queries. For simple cases where we need to iterate over the entity or a single component only, a new enumerator encapsulates all the changed logic while keeping the same performance as before.

For more complex cases, a single iterator can't return multiple values in a performant way. I will address those by injecting the new logic directly in the loops.

Some methods (like query-based add, set, remove) will not support change filtering, so I've added an assertion to reject such queries. This is to avoid confusion, as otherwise the query will affect more entities than expected.

I also added a bunch of new tests, with different combinations of filters.

I still have some work to do but the core it's already in place. I'd appreciate any feedback you have

@genaray
Copy link
Owner

genaray commented Sep 18, 2025

Updated the PR with most of the support for filtering non-changed entities in queries. For simple cases where we need to iterate over the entity or a single component only, a new enumerator encapsulates all the changed logic while keeping the same performance as before.

For more complex cases, a single iterator can't return multiple values in a performant way. I will address those by injecting the new logic directly in the loops.

Some methods (like query-based add, set, remove) will not support change filtering, so I've added an assertion to reject such queries. This is to avoid confusion, as otherwise the query will affect more entities than expected.

I also added a bunch of new tests, with different combinations of filters.

I still have some work to do but the core it's already in place. I'd appreciate any feedback you have

Looks good so far! :) I really appreciate your work!

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.

2 participants