-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Query-level change detection #14510
Copy link
Copy link
Open
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Needs-GoalThis should have a C-Goal and should not continue until it has oneThis should have a C-Goal and should not continue until it has one
Metadata
Metadata
Assignees
Labels
A-ECSEntities, components, systems, and eventsEntities, components, systems, and eventsC-FeatureA new feature, making something new possibleA new feature, making something new possibleD-ComplexQuite challenging from either a design or technical perspective. Ask for help!Quite challenging from either a design or technical perspective. Ask for help!S-Needs-GoalThis should have a C-Goal and should not continue until it has oneThis should have a C-Goal and should not continue until it has one
Type
Projects
Status
Needs SME Triage
What problem does this solve or what need does it fill?
When generating data for things like reactive UI, it's important to be able to quickly and reliably know whether or not a query will return the same things as the last time you checked.
This is also useful as a general-purpose early return or run condition to save on wasted work.
What solution would you like?
The ideal API would look like:
To do this, add a change tick to
QueryStatewhich reflects when matching entities were "most recently added or removed".This value should be kept up to date with observers.
Implementing "when did the values of entities in this query last change" will require combining the structural change tick stored in the query with the mutation change ticks on
What alternative(s) have you considered?
This work fits naturally with making queries entities, and storing their state as components. However, it does not need that work: generating the appropriate observers and storing state should be feasible anyways.
Currently, the only real workaround is to cache the entire query in a
Localor similar. This is both slow and very memory-inefficient.Additional context
This was asked for by @viridia in the context of reactive UI here.
As a nice bonus, this would offer another tool (complementary to ##5097) to make a
any_changedrun condition performant enough to not be a footgun.If this is done as part of the work for #3742, we should be able to hook into the work being done to update the archetype cache.
Otherwise, it may be hard to justify the expense of running observers and updating this data for every query.