-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
As-needed change detection #17629
Draft
SpecificProtagonist
wants to merge
10
commits into
bevyengine:main
Choose a base branch
from
SpecificProtagonist:as-needed-change-detection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
As-needed change detection #17629
SpecificProtagonist
wants to merge
10
commits into
bevyengine:main
from
SpecificProtagonist:as-needed-change-detection
+1,659
−491
Conversation
This file contains 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
SpecificProtagonist
added
C-Feature
A new feature, making something new possible
A-ECS
Entities, components, systems, and events
C-Performance
A change motivated by improving speed, memory usage or compile times
M-Needs-Migration-Guide
A breaking change to Bevy's public API that needs to be noted in a migration guide
X-Contentious
There are nontrivial implications that should be thought through
D-Unsafe
Touches with unsafe code in some way
labels
Feb 1, 2025
alice-i-cecile
added
the
M-Needs-Release-Note
Work that should be called out in the blog due to impact
label
Feb 2, 2025
I would prefer this flavor of design: the "nice" name should be the one returned by default. |
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
C-Performance
A change motivated by improving speed, memory usage or compile times
D-Unsafe
Touches with unsafe code in some way
M-Needs-Migration-Guide
A breaking change to Bevy's public API that needs to be noted in a migration guide
M-Needs-Release-Note
Work that should be called out in the blog due to impact
X-Contentious
There are nontrivial implications that should be thought through
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.
Objective
Make change detection optional in a runtime-configurable way.
See #4882.
For prior art, also see #6659, which statically determined whether query items would be change-detection-enabled based on the type of the component.
Solution
Querying for
&mut T
now gives you aMutMarkChanges<T>
instead of aMut<T>
. This still writes change ticks, but doesn't let you read them. Resources are unchanged.By default, change detection is disabled for all components. It can be manually enabled via
World::enable_change_detection::<T>()
. Using a query with aRef<T>
,Mut<T>
,Added<T>
orChanged<T>
term also enables change detection forT
if not yet enabled, but prints a warning if entities with this component exist (as their change ticks were missed).Updating change ticks via
MutMarkChanges
does not branch: When change detection forT
is disabled, they're instead written to a dummy sink.This PR doesn't turn change ticks into components of their own, which can happen in a followup if desired.
Many methods that previously worked with
Mut
/MutUntyped
now have both a version with and without read access to change ticks (this is responsible for much of the line count; if you review this PR, going commit by commit helps). There's likely some opportunity for deduplication there, but I wanted to go with the simple solution for the initial PR.I'd also be happy to hear about better name suggestions – e.g. should
Mut
be renamed to something likeMutWithTicks
andMutMarkChanges
toMut
(and which one would be easier for migration)?Draft
SystemRegistry
), bad edge cases, or unwieldiness?Testing
(todo)
Showcase
Migration Guide
(todo)