-
-
Notifications
You must be signed in to change notification settings - Fork 21.5k
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
[3.x] Add deferred notifications #65581
Conversation
This breaks compat I guess? Because logic inside For example, godot/scene/2d/skeleton_2d.cpp Lines 62 to 66 in cb0b20b
|
Yes absolutely, I should have emphasised this. 👍 By deferring the notifications till the next flush (currently at the start of the physics tick and frame) there will inevitably be a potential gap in which nodes have a pending notification, if they are processed before the next flush. So there is the potential for regressions which may need fixing / bypassing the system. This is one of those things that is hard to predict the special cases a priori so would turn up through a few betas - there are highly likely to be 2 or 3, most likely resulting in a frame delay in something. However imo the benefits of reducing notifications are significant. The current system is flawed imo - the runaway notifications is clearly nonsense behaviour, so it is well worth working through any regressions to get to a better new stable point. I will try and have a find in files through though and see if there are any more obvious pinchpoints, so we can fix ahead of time. Update:
Out of these the
This is likely having a frame delay already, and it seems like at the moment the deferred notification will worst case create a frame delay, so maybe a 2 frame delay? I'll try and test this. |
6bce782
to
ad9d4ea
Compare
As a result of testing for extra "safety" I've added one extra Should be fine now even with It's possible to check this empirically by checking the queue is empty at the end of |
May it be a good idea to kept that check in debug builds so users can detect and report potential still unprocessed notifications, or can't that reasonably happen at this point? |
Given that deferred notifications could cause regression (we've tried to eliminate but there could be something unforeseen), we could make it optional 🤔 , however I'm not convinced this is totally necessary as it should show up in a beta. |
Wouldn't harm I guess, but it's up to you. |
Looking at it, it's a little ugly to put in |
Makes sense. |
Adds the ability to defer sending notifications to the next flush, instead of sending notifications immediately. This system allows the prevention of duplicate notifications on the same frame / tick, which can result in large numbers of notifications and slowdown.
ad9d4ea
to
f315490
Compare
On thinking about this, I've gone straight for using a pending notification flag instead of storing a tick count (which was mainly for debugging during development anyway). This makes it easier to add future flags (should we decide to do this) without increasing memory use, and is a little easier to understand for a reader. |
Can't we also make |
Marking this as draft (even though approved) to prevent accidental merging, because I am now slightly more favoured towards my newer PR #74672 which solves the same problem in a more targeted way. (I can mark this as ready for review again if reviewers prefer this version though 👍 ). |
Closing in favour of #82248 . |
Adds the ability to defer sending notifications to the next flush, instead of sending notifications immediately. This system allows the prevention of duplicate notifications on the same frame / tick, which can result in large numbers of notifications and slowdown.
Helps address #61929
Alternative to #74672
Notes
NOTIFICATION_MOVED_IN_PARENT
SceneTree
rather than sent directly to the Node. TheSceneTree
keeps lists for each deferred notification type, which can be flushed on frames and physics ticks.Statistics
Using the MRP from #61929, trying with Nodes, blank and filled MeshInstances:
30000 nodes queue_deleted:
Before 20.6 seconds
After 7.06 seconds
Notifications sent:
Before 450 million
After 30000
Discussion and additional methods
This PR essentially replaces the heavyweight notification with a cheaper call, but these cheap calls are still made a lot of times.
An additional technique might be to maintain a list of interested children for each notification type (like observer pattern), but the added complexity and memory use is likely not warranted at this stage. Another problem is that for
NOTIFICATION_MOVED_IN_PARENT
, we are only sending to the children after a certain point in the child list, and this could become expensive unless the subscriber list was also sorted by child index.Another idea is for nodes to register their interest in a notification type (via a set of bitflags), and check this prior to sending the more heavyweight notification.
However although both of these techniques are theoretically possible in core, there is a problem - users must also be able to respond to notifications (either through script or deriving from classes in modules etc), and users would have to register interest / or lack of interest somehow, and thus this might not be doable in a backward compatible way.