Faster queue free

Calling queue_free() for large numbers of siblings could previously be very slow, with the time taken rising exponentially with number of children. This looked partly due to ordered_remove from the child list and notifications.

This PR identifies objects that are nodes, and sorts the deletion queue so that children are deleted in reverse child order. This minimizes the costs of reordering.
This commit is contained in:
lawnjelly
2022-06-11 12:35:32 +01:00
parent d74ff8dd93
commit edc85d22fc
3 changed files with 67 additions and 5 deletions

View File

@@ -510,6 +510,7 @@
<description>
Queues a node for deletion at the end of the current frame. When deleted, all of its child nodes will be deleted as well. This method ensures it's safe to delete the node, contrary to [method Object.free]. Use [method Object.is_queued_for_deletion] to check whether a node will be deleted at the end of the frame.
[b]Important:[/b] If you have a variable pointing to a node, it will [i]not[/i] be assigned to [code]null[/code] once the node is freed. Instead, it will point to a [i]previously freed instance[/i] and you should validate it with [method @GDScript.is_instance_valid] before attempting to call its methods or access its properties.
[b]Note:[/b] For efficiency reasons, the final order of deletion is not guaranteed.
</description>
</method>
<method name="raise">