Skip to content

Optimize NodePath#113447

Merged
Repiteo merged 1 commit into
godotengine:masterfrom
TokageItLab:opt-nodepath
Dec 2, 2025
Merged

Optimize NodePath#113447
Repiteo merged 1 commit into
godotengine:masterfrom
TokageItLab:opt-nodepath

Conversation

@TokageItLab
Copy link
Copy Markdown
Member

co-authored-by: Ryan-000 <73148864+Ryan-000@users.noreply.github.com>
@TokageItLab TokageItLab added this to the 4.x milestone Dec 2, 2025
@TokageItLab TokageItLab requested a review from a team as a code owner December 2, 2025 12:47
@AThousandShips AThousandShips changed the title Optimization NodePath Optimize NodePath Dec 2, 2025
Copy link
Copy Markdown
Member

@Ivorforce Ivorforce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me.

The if condition itself should be almost free1.
In contrast, many paths will probably pass the absolute check, and start comparing path parts. Each indirection could incur cache misses, which are very expensive in comparison2.

The only caveat i have is that I don't know how many NodePath instances have a valid hash cache, so I don't know how often this check will actually help in practice.
But this will be hard to estimate, and like I mentioned, the potential regression vs potential benefit is fairly large, so I think this is fine.

Footnotes

  1. See the cost of comparisons and jumps, both of which are just a few cycles https://www.agner.org/optimize/optimizing_cpp.pdf

  2. See the cost of cache misses https://www.agner.org/optimize/optimizing_cpp.pdf

@Repiteo Repiteo modified the milestones: 4.x, 4.6 Dec 2, 2025
@Repiteo Repiteo merged commit 51d5a17 into godotengine:master Dec 2, 2025
20 checks passed
@Repiteo
Copy link
Copy Markdown
Contributor

Repiteo commented Dec 2, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants