Skip to content

Conversation

cBournhonesque
Copy link
Contributor

Objective

  • Adds uncached queries
  • These queries can be contrasted with the current cached Queries: every time a query operation is done on cached queries, they start by iterating through new archetypes to check which of these new archetypes match the query.
    • when we do an operation on a cached query (iter/get/etc.), we use the cached metadata of sorted archetypes
    • for uncached query, we instead go through world archetypes from scratch to check which archetypes match the query. Note that we do not go through all the archetypes because we can use the ComponentIndex to reduce the number of archetypes that we have to go through.

Solution

  • Implements uncached queries by adding a 3rd generic QueryCache to QueryState. That generic can essentially have 2 values: CacheState or Uncached.

I opted for this so that:

  • we statically know if the query is cached or uncached so we don't pay the cost of if is_cached() calls
  • we don't need to write new implementations for all the QueryState functions, only a couple of functions change and are implemented differently for QueryState<CacheState> vs QueryState<Uncached>

NOTE:

  • the PR is still WIP (I'm getting some lifetime issues when trying to create the QueryIterationCursor object + it needs some polishings, tests, benchmarks)

@james-j-obrien
Copy link
Contributor

Ignoring the WIP nature of the PR, this seems like broadly the correct approach to me i.e. splitting up the query state such that the "cache" portion is responsible for managing a list of storages to iterate.

Having an additional generic on all these query related structs and traits is an ergonomic hit, the bigger these definitions get the "scarier" they get in the sense that they become harder and harder to grok, but none of the alternatives are free either.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-ECS Entities, components, systems, and events M-Needs-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Oct 20, 2025
Copy link
Contributor

It looks like your PR has been selected for a highlight in the next release blog post, but you didn't provide a release note.

Please review the instructions for writing release notes, then expand or revise the content in the release notes directory to showcase your changes.

@alice-i-cecile
Copy link
Member

As SME-ECS, I'm broadly on board with this direction and excite to see this evolve!

@cBournhonesque
Copy link
Contributor Author

Updated the PR to make the tests pass.

Things i'd like to change:

  • ideally not add a 3rd generic to QueryState
  • we realistically only have 2 implementations for QueryCache, so maybe we don't need a trait
  • split_cache is very unsafe and miri errors on it
  • maybe we can just have a UncachedQuery and a CachedQuery that contains it + the cache?

@alice-i-cecile
Copy link
Member

maybe we can just have a UncachedQuery and a CachedQuery that contains it + the cache?

This seems like a simpler design. Explore that and report back?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-ECS Entities, components, systems, and events C-Feature A new feature, making something new possible M-Needs-Release-Note Work that should be called out in the blog due to impact S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants