KSP-RO / TestFlight

KSP Mod that provides a part research and reliability system
42 stars 31 forks source link

Performance Tweaks and Refactoring #243

Closed DRVeyl closed 2 years ago

DRVeyl commented 2 years ago

Generalized Performance Tweaks: Avoid duplicating base method code when calling them from overridden methods Pay greater attention to string allocations & unguarded stack trace builds Build constant arrays outside of loops Avoid extra calls to ToLower() and similar, especially when using StringCompare.OrdinalIgnoreCase Extract flightData, transferData, researchData, and flightTime from the generalized string dictionary that requires constant parsing/ToString to eliminate GC pressure. Cache TestFlightCore.Alias Result Convert PartStatus from struct to class, pass by reference / modify in place Use part.FindModuleImplementing instead of iterating ourselves. It caches in latest KSP.

Generalized code pattern tweaks: Use class initializer for List Use interpolated strings Use foreach Use Dictionary.TryGetValue Remove unneeded overrides (OnAwake, OnEnable, OnSave) that only ever call the base. Remove dead code Switch to StringCompare.OrdinalIgnoreCase Don't return null instead of empty Lists in ModuleGetters (Reliability, Failure, etc).

Maintenance Tasks: Make SettingsEnabled, SettingsAlwaysMaxData common settings KSPFields. Declare fields [Persistent] and use ConfigNode static methods to save/load objects instead of manually writing/parsing the values to/from the node. Refactor the Getters/Setters into simpler pattern. These methods should now be unused outside of TestFlightPartData.cs itself, but remain for compatibility Declare some fields [Persistent] and use ConfigNode static methods to save/load objects instead of manually writing/parsing the values to/from the node. Refactor random failure logic Make tool for hand-written reflection invocations that checked for the TF core, installation status, readiness, then invoked a chosen method

Bugfixes: Fix GetWorstMomentaryFailureRate to get the worst rate instead of the last rate Fix some NREs

github-actions[bot] commented 2 years ago

Download the artifacts for this pull request: