Make the $ operator in GDScript cache node references (or add a $$ operator)
EDIT: ~~If #1048 is implemented, it may make this proposal obsolete.~~ EDIT 2: As @h0lley noted, #1048 doesn't actually make this proposal obsolete. It provides a clean alternative but it still results in boilerplate and a lack of green syntax highlighting unlike this proposal. **Describe the project you are working on:** https://github.com/godotengine/godot-demo-projects/ but this applies to any project made in GDScript. **Describe the problem or limitation you are having in your project:** Here is a code snippet from Dodge the Creeps:  The problem is that this code looks elegant, but it isn't very performant. Every time this method is called, it has to call `get_node()` 6 times, and 2 of those times are getting the same node (HUD). We can reduce this from 6 to 5 by caching the HUD reference like this:  However, this method is still very inefficient, since it calls `get_node()` 5 times every time the method is ran. The best simple option that I can see is to use `onready var` like this:  This means that `get_node()` is only called 5 times once when this node is created,
Posted by aaronfranke on Jun 2, 2020, 7:35 PM
Tags
Related issues
- [Meta] Feedback on granular control over Copilot changes
- unexpected status 401 Unauthorized issue
- [MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
- [CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
- Video stops playing after some minutes
- [MODEL] Claude verbose code comments by default — ignores instructions to stop.
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
github (Software)
[Meta] Feedback on granular control over Copilot changes
unexpected status 401 Unauthorized issue
[MODEL] Measurable quality regression in Claude generation 5 (Fable 5 / Opus 5 / Sonnet 5): worse nonsense detection, ~2x verbosity, under-disclosed model fallb
[CRITICAL] Subagent spawning and subagent pattern bugs trigger infinite recursion, infinite token usage, grossly inefficient token usage, and lost accumulated s
Video stops playing after some minutes
[MODEL] Claude verbose code comments by default — ignores instructions to stop.
Scope Codex VS Code chats to the current workspace/project
Update on "Co-authored-by: Copilot" in commit messages
Make the $ operator in GDScript cache node references (or add a $$ operator)
EDIT: ~~If #1048 is implemented, it may make this proposal obsolete.~~ EDIT 2: As @h0lley noted, #1048 doesn't actually make this proposal obsolete. It provides a clean alternative but it still results in boilerplate and a lack of green syntax highlighting unlike this proposal. **Describe the project you are working on:** https://github.com/godotengine/godot-demo-projects/ but this applies to any project made in GDScript. **Describe the problem or limitation you are having in your project:** Here is a code snippet from Dodge the Creeps:  The problem is that this code looks elegant, but it isn't very performant. Every time this method is called, it has to call `get_node()` 6 times, and 2 of those times are getting the same node (HUD). We can reduce this from 6 to 5 by caching the HUD reference like this:  However, this method is still very inefficient, since it calls `get_node()` 5 times every time the method is ran. The best simple option that I can see is to use `onready var` like this:  This means that `get_node()` is only called 5 times once when this node is created,
Comments (0)
No comments yet. Start the discussion.