Optimize NodePath to String by using cached path#110478
Merged
Repiteo merged 1 commit intogodotengine:masterfrom Oct 23, 2025
Merged
Optimize NodePath to String by using cached path#110478Repiteo merged 1 commit intogodotengine:masterfrom
Repiteo merged 1 commit intogodotengine:masterfrom
Conversation
Ivorforce
approved these changes
Sep 13, 2025
Member
There was a problem hiding this comment.
Makes sense to me. We have caches, so we should be using them.
Note that I expect this to be slower on the first conversion to String, but I think that's an acceptable trade-off. We can optimize the get_concatenated_names and get_concatenated_subnames functions in a future PR (e.g. with reserve).
b2d7d85 to
d16413a
Compare
beicause
commented
Sep 13, 2025
| void NodePath::prepend_period() { | ||
| if (data->path.size() && data->path[0].operator String() != ".") { | ||
| data->path.insert(0, "."); | ||
| data->concatenated_path = StringName(); |
Contributor
Author
There was a problem hiding this comment.
I'm surprised we didn't clear the cache when modifying the NodePath. Perhaps we don't have cases where NodePath is modified after calling get_concatenated_names, but this is a potential bug.
Contributor
There was a problem hiding this comment.
Might be good to write a test case for that as well, NodePath should be easy to test
Contributor
|
Thanks! |
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.
Found this problem when I'm working on #110439 (This code doesn't consider absolute path, which maybe wrong):
godot/scene/resources/animation.cpp
Line 1067 in bfa330d
We can optimize NodePath to String by using the cached concatenated path.
Tested in gdscript
Before: 702, After: 373