Skip to content

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

Merged
gotmachine merged 3 commits into
devfrom
FasterPartFindTransform
Oct 12, 2024
Merged

Faster FindModelTransform*() and FindHeirarchyTransform*()#255
gotmachine merged 3 commits into
devfrom
FasterPartFindTransform

Conversation

@gotmachine
Copy link
Copy Markdown
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
@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