KerbalEngineer icon indicating copy to clipboard operation
KerbalEngineer copied to clipboard

Cost calculation run even during flight

Open siimav opened this issue 5 years ago • 1 comments

This can cause a significant performance impact when the user has tons of mods. Calls to Part.GetModuleCosts means that KSP iterates over all the PartModules that the part has to find the ones that implement IPartCostModifier. To make matters worse, some mods can have quite substantial functionality inside the cost modifer code. I would suggest not querying the part costs inside the simulations because that info is not relevant inside the flight scene anyway. Here's the stack where KER queries the part cost:

   at Part.GetModuleCosts(Single defaultCost, ModifierStagingSituation sit)
   at KerbalEngineer.Extensions.PartExtensions.GetCostDry(.Part part)
   at KerbalEngineer.VesselSimulator.PartSim.New(.Part p, Int32 id, Double atmosphere, KerbalEngineer.LogMsg log)
   at KerbalEngineer.VesselSimulator.Simulation.PrepareSimulation(KerbalEngineer.LogMsg _log, System.Collections.Generic.List`1 parts, Double theGravity, Double theAtmosphere, Double theMach, Boolean dumpTree, Boolean vectoredThrust, Boolean fullThrust)
   at KerbalEngineer.VesselSimulator.SimManager.StartSimulation()
   at KerbalEngineer.VesselSimulator.SimManager.TryStartSimulation()
   at KerbalEngineer.Editor.BuildAdvanced.Update()

siimav avatar May 28 '19 17:05 siimav

Is there any reason to calculate the cost ever? I'm looking through the code and I don't see where it's used.

I just edited out every reference to cost and I don't seem to see any changes yet either (either performance gains or new bugs).

MacKenzieHnC avatar Apr 19 '21 23:04 MacKenzieHnC