Skip to content

[3.x] Optimize hotspots with Object::derives_from #107881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented Jun 23, 2025

Un-exposes ancestry (so it becomes internal), and instead exposes Object::_is_class via a rename to Object::derives_from.

Applies in some use cases.

Object::derives_from() should be in a lot of cases 1.5x faster in release builds than using cast_to() (when a NULL check is not necessary), and will be faster in DEV builds (without optimization). It will also be faster than Object::is_class(String) by a huge margin (although we are only worried about hotspots here).

Notes

  • This is something discussed with @Ivorforce , we can now totally totally hide the ancestry system as internal, and use it to accelerate Object::cast_to and Object::derives_from.
  • These functions have the advantage that they will accelerate the classes in AncestralClass enum / bitfield, but they will also work with all other classes via the backup GDSOFTCLASS system.
  • Aim is to do the same in 4.x.
  • I haven't converted all the Object::is_class() uses.
    Object::is_class() is still useful for backward compatibility, calling from script (where we don't have an enum of all Object types) and for non-bottleneck areas such as the Editor where we can avoid creating include dependencies.

@lawnjelly lawnjelly added this to the 3.7 milestone Jun 23, 2025
@lawnjelly lawnjelly requested review from a team as code owners June 23, 2025 07:52
@lawnjelly lawnjelly requested review from a team as code owners June 23, 2025 07:52
Copy link
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.

Should be a straight upgrade.

@lawnjelly lawnjelly merged commit 784f92a into godotengine:3.x Jun 23, 2025
14 checks passed
@lawnjelly
Copy link
Member Author

Thanks!

@lawnjelly lawnjelly deleted the derives_from branch June 23, 2025 09:42
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.

2 participants