[3.x] Deferred NOTIFICATION_MOVED_IN_PARENT and register interest #74672
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.
Adds the ability to defer sending
NOTIFICATION_MOVED_IN_PARENT
to the next flush, instead of sending notifications immediately. This system allows the prevention of duplicate notifications on the same frame, which can result in large numbers of notifications and slowdown.For efficiency, stores the range of children moved on the parent node, rather than storing each child individually.
Additionally 2D nodes register an interest in observing
NOTIFICATION_MOVED_IN_PARENT
, this is tested before sending the final notification.Use in conjunction with #65581
Helps address #61929 (specifically the non-deletion cases)
Flushes
As this PR is only concerned with
MOVED_IN_PARENT
I've experimentally tried only flushing the notifications once prior to rendering, rather than every physics tick as in #65581 . The notification is used in three areas, and I'm not convinced yet it requires flushing except prior to rendering (and no testing so far suggests this).Given that it is easy enough to add the flushes in during physics tick (one line), it is probably worth trying this out for a beta with a single flush. The reasoning is that we do flush each tick, if items are moved several times during multiple physics ticks before a frame, their canvas_item order ID will be sent multiple times (needlessly) to
VisualServer
.Notes
notification()
call is rather heavyweight, calling functions on each class in the inheritance hierarchy as well as potentially script.canvas_item
. Even in this case in a heavily modded version of Godot, then a call to_set_observe_notification_moved_in_parent()
is enough to re-establish the old behaviour, so on balance it seems worth doing, given the benefits.Performance
As with #65581 this drastically reduces notifications, and even more so because of the range optimization specific to
NOTIFICATION_MOVED_IN_PARENT
.Which alternative
Both versions address the problem pretty well - #65581 is more generic and future proof, whereas this PR is more efficient but only designed for this single problematic notification.
Personally I would probably be tempted to go for this version, as we are unlikely to need more deferred notification types in 3.x, and it should be more efficient.