Kerbal Engineer Redux

Kerbal Engineer Redux

2M Downloads

Cost calculation run even during flight

siimav opened this issue ยท 1 comments

commented

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()
commented

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).