diff --git a/KSPCommunityFixes/Performance/MinorPerfTweaks.cs b/KSPCommunityFixes/Performance/MinorPerfTweaks.cs index a3117ba..5a35270 100644 --- a/KSPCommunityFixes/Performance/MinorPerfTweaks.cs +++ b/KSPCommunityFixes/Performance/MinorPerfTweaks.cs @@ -16,6 +16,9 @@ protected override void ApplyPatches() AddPatch(PatchType.Override, typeof(Part), nameof(Part.isKerbalEVA)); AddPatch(PatchType.Override, typeof(VolumeNormalizer), nameof(VolumeNormalizer.Update)); + + AddPatch(PatchType.Override, typeof(MonoUtilities), nameof(MonoUtilities.RefreshContextWindows)); + AddPatch(PatchType.Override, typeof(MonoUtilities), nameof(MonoUtilities.RefreshPartContextWindow)); } // When FlightGlobals._fetch is null/destroyed, the stock "fetch" getter fallback to a FindObjectOfType() @@ -89,5 +92,21 @@ private static void VolumeNormalizer_Update_Override(VolumeNormalizer vn) vn.volume = newVolume; } + + // MonoUtilities.RefreshContextWindows calls Object.FindObjectsOfType. + // This is quite slow. The method is not used in stock but several mods + // do use it and it would otherwise take up a notable chunk of scene + // switch times. + private static void MonoUtilities_RefreshContextWindows_Override(Part part) + { + if (part.IsNotNullRef() && part.PartActionWindow.IsNotNullOrDestroyed()) + part.PartActionWindow.displayDirty = true; + } + + private static void MonoUtilities_RefreshPartContextWindow_Override(Part part) + { + if (part.IsNotNullRef() && part.PartActionWindow.IsNotNullOrDestroyed()) + part.PartActionWindow.displayDirty = true; + } } }