Skip to content

Conversation

@Phantomical
Copy link

When you launch out of the VAB, FlightDriver.setStartupNewVessel ends up starting all PQS instances twice. The initial start of PQS is very expensive, and all the work done on the first call is basically thrown away.

This patches FlightDriver.setStartupNewVessel to avoid calling PSystemSetup.SetActive a second time. This is just a matter of patching the 3 different calls to shims that track whether they have been called.

How much this actually ends up saving depends on the planet and mods installed. For stock I expect this to be about 2s, for the Sol install I'm testing (with a whole bunch of other patches to various mods) it is about 2.5s.

Before

image

After

image

@Phantomical Phantomical changed the title Avoid second call to SetActive in FlightDriver.setStartupNewVessel Avoid duplicate call to PSystemSetup.SetActive in FlightDriver.setStartupNewVessel Jan 4, 2026
@siimav
Copy link
Contributor

siimav commented Jan 4, 2026

Does it help in practice (i.e outside the profiler) too? With Plain Old RSS the results with this patch disabled vs enabled are within measurement error.

@Phantomical
Copy link
Author

I'm wondering if this is somewhat specific to launch sites in Sol, or if there's just something that causes it to only happen under some conditions.

I would have expected somebody to notice this before now (me included) if it happened regularly.

I'll do some more profiling here to see if it happens in stock

@Phantomical
Copy link
Author

Phantomical commented Jan 5, 2026

Some quick testing on a (mostly) stock shows that this is definitely happening. I don't think I have anything installed on this new testing save that would affect the results here. Looking at the code this should happen any time you launch from the VAB or SPH and the launchsite is a PQSCity or a PQSCity2. @siimav what did your test setup look like?

image

Comparison with patch enabled

image

The launch does feel noticeably faster to me - which makes sense since it seems to nearly be a 4s improvement. I'll configure up a fully stock + KSPCF install and give it another test.

edit: Gave it a spin in a stock + KSPCF install and I can definitely still see it happening along with the improvement from this PR. My setup is that I'm profiling rolling out a new ship from the VAB.

When you launch out of the VAB, FlightDriver.setStartupNewVessel ends up
starting all PQS instances twice. The initial start of PQS is very
expensive, and all the work done on the first call is basically thrown
away.

This patches `FlightDriver.setStartupNewVessel` to avoid calling
`PSystemSetup.SetActive` a second time. This is just a matter of
patching the 3 different calls to shims that track whether they have
been called.
@siimav
Copy link
Contributor

siimav commented Jan 5, 2026

Rerun the tests with a SB save instead of career and with a single part vessel to minimize all the rest of the overhead.
4 runs for patch off vs on, VAB to flight time in seconds:
6.4 -> 5.8
5.9 -> 5.5
6.0 -> 5.2
6.0 -> 5.3

I guess there are some gains. Just easy to lose those within all the rest that usually happens on scene changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants