Skip to content
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

Faster FindModelTransform*() and FindHeirarchyTransform*() #255

Merged
merged 3 commits into from
Oct 12, 2024

Conversation

gotmachine
Copy link
Contributor

Faster, and minimal GC alloc relacements for the Part FindModelTransform* and FindHeirarchyTransform* methods.

Roughly 4 times faster on average for callers in a stock install, but this can go up to 20x faster on deep hierarchies.

The main trick is to use Transform.Find() instead of checking the Transform.name property (which will allocate a new string) for every transform in the hierarchy. There are a few quirks with Transform.Find() requiring additional care, but this is overall much faster and eliminate GC allocations almost entirely.

Even though they are mostly "init-time" methods, they are used quite a bit in stock, and massively over the modding ecosystem, so this can help with loading time and scene switches : https://github.com/search?q=FindModelTransform+OR+FindModelTransforms+language%3AC%23&type=code

…orm* and FindHeirarchyTransform* methods.

Roughly 4 times faster on average for callers in a stock install, but this can go up to 20x faster on deep hierarchies.
@gotmachine gotmachine changed the title Faster FindModelTransform*() and vFindHeirarchyTransform*()` Faster FindModelTransform*() and FindHeirarchyTransform*() Oct 7, 2024
@gotmachine gotmachine changed the base branch from master to dev October 7, 2024 12:30
@gotmachine gotmachine added the kspPerformance Possible performance improvement in KSP label Oct 7, 2024
@gotmachine gotmachine merged commit 6948692 into dev Oct 12, 2024
1 check passed
@gotmachine gotmachine deleted the FasterPartFindTransform branch October 12, 2024 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kspPerformance Possible performance improvement in KSP
Development

Successfully merging this pull request may close these issues.

1 participant