Implement NodePool optimization with NOTIFY_PREDELETE for automatic node recycling#184
Open
Implement NodePool optimization with NOTIFY_PREDELETE for automatic node recycling#184
Conversation
…ode recycling Co-authored-by: krazyjakee <623463+krazyjakee@users.noreply.github.com>
… and comprehensive documentation Co-authored-by: krazyjakee <623463+krazyjakee@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Prevent NodePool nodes being frees
Implement NodePool optimization with NOTIFY_PREDELETE for automatic node recycling
Sep 29, 2025
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR implements automatic node recycling for NodePool using Godot's
NOTIFY_PREDELETEnotification system, allowing developers to usequeue_free()normally while nodes are automatically returned to the pool instead of being destroyed.Problem
Currently, NodePool requires explicit code to return nodes to the pool, making game code pool-aware and complicating memory management:
Solution
The new
PooledNodebase class leveragesNOTIFY_PREDELETEto interceptqueue_free()calls and automatically return nodes to their pool:Key Features
Transparent Operation: Game code can use
queue_free()as normal without pool awarenessAutomatic Recycling: Nodes are intercepted before deletion and returned to pool
Memory Optimization: Reduces allocations and garbage collection pressure
Backward Compatible: Existing NodePool usage continues to work unchanged
Robust Error Handling: Prevents double-returns and handles edge cases safely
Implementation Details
_notification()to catchNOTIFY_PREDELETE, callscancel_free(), and returns to poolowner_poolreferences and providesreturn_to_pool()method with proper state managementreset_for_pool()when nodes are returned to ensure clean reuseUsage Example
Benefits for Game Development
queue_free()callsThis optimization is particularly valuable for systems like bullet holes, particle effects, projectiles, and UI elements that are frequently created and destroyed during gameplay.
Testing
Includes comprehensive unit tests and integration tests to verify automatic recycling, pool limits, state reset, and edge case handling. The implementation has been designed to be robust and fail gracefully.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.