-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Text change detection split #19438
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
base: main
Are you sure you want to change the base?
Text change detection split #19438
Conversation
…_needs_rerender` and `detect_text_spawn_needs_rerender`. This avoids checking `TextSpan` nodes for changes twice.
// Potential conflict: `Assets<Image>` | ||
// Since both systems will only ever insert new [`Image`] assets, | ||
// they will never observe each other's effects. | ||
.ambiguous_with(bevy_text::update_text2d_layout) | ||
// We assume Text is on disjoint UI entities to ImageNode and UiTextureAtlasImage | ||
// FIXME: Add an archetype invariant for this https://github.com/bevyengine/bevy/issues/1481. | ||
.ambiguous_with(widget::update_image_content_size_system), | ||
.ambiguous_with(widget::update_image_content_size_system) | ||
.after(detect_text_span_needs_rerender), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means text span rerender detection is not locked into the UiSystems
system sets. Which means systems in PostUpdate
that deal with text stuff .before(UiSystems::Prepare)
could be ordered wrong relative to text span rerender detection.
Can you move detect_text_span_needs_rerender
to a system set then in this plugin do .configure_sets(PostUpdate, TextSpanDetectSet.in_set(UiSystems::Content)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although that may screw up text2d
ordering. Which is might be why I originally allowed duplicate text span change detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although that may screw up
text2d
ordering. Which is might be why I originally allowed duplicate text span change detection.
I guess we could work around this a different way, maybe by adding a Has<Root>
to the computed
query? Walking all the text spans twice feels really unpleasant though, even if it's cheap in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think Has<Root>
in computed
would change anything. Afaict we have these options:
- This PR with ordering constraints. Will couple text2d and UI system ordering, possibly losing parallelism.
- Invert the loop and traverse down from roots, manually checking for changed spans. This may be less performant than simply iterating spans twice, since hierarchy traversal is an order of magnitude more expensive per entity IIRC (hashmap lookup vs vec indexing, approximately).
- Change nothing. Continue to iterate all spans twice.
Objective
The
detect_text_needs_rerender
system runs twice, once querying for allText
root UI node entities and once querying for allText2d
2d root entities. But both times it queries for allTextSpan
s. This causes two problems:All
TextSpan
s are checked twice for changes.If there is an error with a
TextSpan
,detect_text_needs_rerender::<Root>
reports the currentRoot
type parameter:But since the system checks all
TextSpan
s for both root types, the reported root type is determined by the system order. Not the type of the specificTextSpan
's root.Fixes #19437
Solution
Split
detect_text_needs_rerender
into two systemsdetect_text_root_needs_rerender
anddetect_text_span_needs_rerender
.detect_text_root_needs_rerender
runs twice, once forText
and once forText2d
, whiledetect_text_span_needs_rerender
only runs once.The root type has been removed from all the warnings. I considered adding
Has<Text>
andHas<Text2d>
parameters but this already quite convoluted and I don't think identifying the type of root is very useful here. Also it wouldn't be compatible with a custom text implementation using alternative root components.Testing
With line 114 of
many_buttons
changed to:run
many_buttons
has noText2d
entities but you can seedetect_text_root_needs_rerender::<Text2d>
on main doing work:The result looks exciting but this is with an unrealistically large number of text sections. For normal apps though the improvements won't be measurable and they might even be exceeded by the overhead of the new
detect_text_span_needs_rerender
system. The fix for the deceptive warnings is the more important part of this PR.