-
Notifications
You must be signed in to change notification settings - Fork 20
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
Lots of time spent in GetAnyBodyProgress due to Enum.GetValues #100
Comments
That's a great find! Are you up to making a PR? It looks like it'd be a fairly simple transpiler patch, just replace the Enum.GetValues() call with a ldfld and a bunch of noops. |
EDIT: And store the result in a static readonly field in the patch class to ldfld from, obvs. |
Yeah, I can give it a shot |
Awesome! Thank you! Should be quite easy, you can probably just duplicate the Strategy Duration patch, move the cs to Performance and rename the filename/class, add a new entry to settings.cfg in performance and set it true, and then change the code to have just one transpiler that hits the method in question. Holler if I can help further! :) |
Unrelated, but what toolset are you using for profiling ? Those screenshots don't look like the Unity profiler... |
Haven't had any time to work on this yet so if you have free time go ahead and implement! I use DotTrace for profiling, more habit than anything else probably, it has built in Unity support. |
Took me a bit of time to actually find a contract triggering calls to At least in the rover construction contract (didn't check the comet sample) it is called once per body per update, so the overhead is indeed significant (especially if you have a larger than stock body count). Turning the For the rover construction contract in a non-debug stock install, per frame overhead of the method went from 0.497 ms to 0.016 ms, so definitely a worthy fix. Beside the Enum.GetValue() overhead, the method is uselessly throwing away a new instance of the |
Oh only the two contracts, well still that's a big gain if someone has one being offered! Thank you a bunch for fixing, sorry I never got to it myself! |
I'm new to KSP modding so apologies if this is just my system, or because of a debug build, or already known, etc!
I ran a profiler on my (heavily modded) KSP installation, and one vanilla function stood out to me,
GetAnyBodyProgress
. The function seems simple, but a lot of time is just spent callingEnum.GetValues(typeof(ProgressType))
every time. If this was simply cached, I'd imagine the function would speed up a bunch.Rough decompiled vanilla code:
This is when I was in the tracking station (was trying to see why that was particularly slow for me).
Seems like a potentially simple fix - I've done Harmony patching for RimWorld before.
The text was updated successfully, but these errors were encountered: