Code Monkey home page Code Monkey logo

Comments (4)

ducakar avatar ducakar commented on August 22, 2024

FindObjectsOfType() call in ModuleKISInventory.cs:835 seems to be the cause of this. Functions like Object.FindObjectsOfType(), Resources.FindObjectsOfTypeAll() etc. are extremly slow and should be avoided whereever possible, especially in methods that are called per-frame. A single such call per frame has drastic impact on framerate.

from kis.

smjjames avatar smjjames commented on August 22, 2024

I've gotten this as well.

Theres also some camera wierdness going on in the VAB.SPH that might be related.

The lag is particularily bad when at a base that is already laggy

from kis.

xEvilReeperx avatar xEvilReeperx commented on August 22, 2024

The call to FindObjectsOfType in ModuleKISInventory can be eliminated by adding a component to the window prefab which updates a static list of open UIPartActionWindows. Example:

[KSPAddon(KSPAddon.Startup.EditorAny, true)]
public class InitPartActionWindowTracker : MonoBehaviour
{
    private void Awake() { UIPartActionWindowTracker.Init(); }
}

[KSPAddon(KSPAddon.Startup.Flight, true)]
public class FlightBootstrapper : InitPartActionWindowTracker
{
}


public class UIPartActionWindowTracker
{
    private class WindowTrackerComponent : MonoBehaviour
    {
        private void Awake() { Add(GetComponent<UIPartActionWindow>()); }
        private void OnDestroy() { Remove(GetComponent<UIPartActionWindow>()); }
    }


    public static readonly List<UIPartActionWindow> Windows = new List<UIPartActionWindow>();

    public static void Init()
    {
        if (UIPartActionController.Instance.windowPrefab.gameObject.GetComponent<WindowTrackerComponent>() == null)
            UIPartActionController.Instance.windowPrefab.gameObject.AddComponent<WindowTrackerComponent>();
    }

    private static void Add(UIPartActionWindow window)
    {
        if (window != null && !Windows.Contains(window))
            Windows.Add(window);
    }

    private static void Remove(UIPartActionWindow window)
    {
        if (window != null && Windows.Contains(window))
            Windows.Remove(window);
    }
}

Then this line:

foreach (var window in GameObject.FindObjectsOfType(typeof(UIPartActionWindow))
.OfType<UIPartActionWindow>().Where(p => p.Display == UIPartActionWindow.DisplayType.Selected))

could be changed to

foreach (var window in UIPartActionWindowTracker.Windows.Where(p => p.Display == UIPartActionWindow.DisplayType.Selected)

and avoid the performance penalty

from kis.

KospY avatar KospY commented on August 22, 2024

Fixed for next version (1.0.1)

from kis.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.