Skip to content

perf: Load expansion bundles asynchronously in the background#345

Merged
JonnyOThan merged 3 commits into
KSPModdingLibs:devfrom
Phantomical:async-extension-loading
Nov 18, 2025
Merged

perf: Load expansion bundles asynchronously in the background#345
JonnyOThan merged 3 commits into
KSPModdingLibs:devfrom
Phantomical:async-extension-loading

Conversation

@Phantomical
Copy link
Copy Markdown
Collaborator

This commit completely overrides ExpansionLoader so that asset bundles are loaded in async and in parallel while part compilation is being done. These take a really long time to decompress so it isn't able to completely hide the latency but it seems to improve overall loading time by ~10s on a stock + KSPCF install. As the time taken in part compilation increases the time saved should continue to improve until part compilation takes longer than about 13s, which is how long it takes to unload the serenity_assets asset bundle.

The implementation details are:

  • we now start our own LoadExpansionsV2 coroutine immediately after patching which waits one frame then starts async background loads of all the asset bundles
  • once the bundles are loaded the coroutine waits until StartLoad is called and then goes and does the normal load for each of the expansion bundles in the usual order.
  • I have also moved checksum calculations off to a background thread, though I doubt this makes much of a difference.

I haven't tried to optimize anything else other than moving the asset bundle load off the main thread because I don't think there's much worth optimizing there.

Other compatibility notes:

  • this patch disables itself if the OptionalMakingHistoryDLCFeatures patch is enabled and configured to skip loading of the expansions.

Comparison

Ignore total load times as they include time taken for me to click the png caching popup

Before:

[KSPCF:FastLoader] 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz | 65371 MB | NVIDIA GeForce RTX 3060 (12110 MB)
Total loading time to main menu : 121.922s
- Configs and assemblies loaded in 5.567s
- Configs reload done in 1.314s
- Configs translated in 0.021s
- 2927 assets loaded in 6.401s :
  - 86 audio assets (79.689 MiB) in 0.219s, 363.323 MiB/s
  - 2188 texture assets (1.297 GiB) in 5.566s, 238.623 MiB/s
  - 652 model assets (66.516 MiB) in 0.614s, 108.269 MiB/s
- Asset bundles loaded in 4.960s
- GameDatabase (configs, resources, traits, upgrades...) loaded in 0.184s
- Built-in parts copied in 0.024s
- Part and internal configs extracted in 0.002s
- 503 parts and 2013 modules compiled in 14.037s
  - 4.0 modules/part, 27.907 ms/part, 6.973 ms/module
  - PartIcon compilation : 1.135s
- 27 internal spaces and 56 props compiled in 0.218s
- 2 DLC (Making History, Breaking Ground) loaded in 23.400s
- Planetary system loaded in 8.625s

After:

[KSPCF:FastLoader] 11th Gen Intel(R) Core(TM) i7-11700K @ 3.60GHz | 65371 MB | NVIDIA GeForce RTX 3060 (12110 MB)
Total loading time to main menu : 49.782s
- Configs and assemblies loaded in 5.602s
- Configs reload done in 1.247s
- Configs translated in 0.019s
- 2927 assets loaded in 6.984s :
  - 86 audio assets (79.689 MiB) in 0.314s, 253.821 MiB/s
  - 2188 texture assets (1.297 GiB) in 6.009s, 221.019 MiB/s
  - 652 model assets (66.516 MiB) in 0.658s, 101.085 MiB/s
- Asset bundles loaded in 4.974s
- GameDatabase (configs, resources, traits, upgrades...) loaded in 0.194s
- Built-in parts copied in 0.023s
- Part and internal configs extracted in 0.002s
- 503 parts and 2013 modules compiled in 4.238s
  - 4.0 modules/part, 8.426 ms/part, 2.106 ms/module
  - PartIcon compilation : 1.243s
- 27 internal spaces and 56 props compiled in 0.233s
- 2 DLC (Making History, Breaking Ground) loaded in 9.086s
- Planetary system loaded in 8.839s

@Phantomical Phantomical force-pushed the async-extension-loading branch from 9aa81e3 to 2f5d5bf Compare November 17, 2025 07:11
This commit completely overrides ExpansionLoader so that asset bundles
are loaded in async and in parallel while part compilation is being
done. These take a _really_ long time to decompress so it isn't able to
completely hide the latency but it seems to improve overall loading time
by ~10s on a stock + KSPCF install. As the time taken in part
compilation increases the time saved should continue to improve until
part compilation takes longer than about 13s, which is how long it takes
to unload the `serenity_assets` asset bundle.

The implementation details are:
- we now start our own LoadExpansionsV2 coroutine immediately after
  patching which waits one frame then starts async background loads
  of all the asset bundles
- once the bundles are loaded the coroutine waits until StartLoad is
  called and then goes and does the normal load for each of the
  expansion bundles in the usual order.
- I have also moved checksum calculations off to a background thread,
  though I doubt this makes much of a difference.

I haven't tried to optimize anything else other than moving the asset
bundle load off the main thread because I don't think there's much worth
optimizing there.

Other compatibility notes:
- this patch disables itself if the OptionalMakingHistoryDLCFeatures
  patch is enabled and configured to skip loading of the expansions.
@Phantomical Phantomical force-pushed the async-extension-loading branch from 2f5d5bf to 42eb4d6 Compare November 17, 2025 07:41
@JonnyOThan
Copy link
Copy Markdown
Contributor

Is this ready to go or did you want to look at kicking it off earlier in the loading process?

@JonnyOThan JonnyOThan changed the base branch from master to dev November 17, 2025 20:39
@Phantomical
Copy link
Copy Markdown
Collaborator Author

This should be ready to go. Moving it earlier can come in a follow-up PR.

@JonnyOThan JonnyOThan merged commit f225ae7 into KSPModdingLibs:dev Nov 18, 2025
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