Skip to content

Commit f225ae7

Browse files
perf: Load expansion bundles asynchronously in the background (#345)
* perf: Load expansion bundles asynchronously in the background 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. * Update CHANGELOG with new performance patch --------- Co-authored-by: JonnyOThan <jonnyothan@gmail.com>
1 parent ce92223 commit f225ae7

4 files changed

Lines changed: 390 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
##### Unreleased
44
**New/improved patches**
5+
- New performance patch: [**ExpansionBundlePreload**](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/345) : Loads DLC assetbundles asynchronously, saving several seconds during loading if DLC is installed. Thanks @Phantomical!
56
- **MinorPerfTweaks** [now includes a patch to make PQS loading faster](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/343) on scene switches, saving ~1 second when switching from KSC to a vessel. Thanks @Phantomical!
67
- **MinorPerfTweaks** [now includes a patch to optimize refreshing part context windows](https://github.com/KSPModdingLibs/KSPCommunityFixes/pull/338). Thanks @Phantomical!
78

GameData/KSPCommunityFixes/Settings.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,9 @@ KSP_COMMUNITY_FIXES
492492
// Improve the responsiveness of the part list when switching between categories, sorting and searching by tag.
493493
FasterEditorPartList = true
494494

495+
// Load the expansion bundles in the background while performing part compilation.
496+
ExpansionBundlePreload = true
497+
495498
// ##########################
496499
// Modding
497500
// ##########################

KSPCommunityFixes/KSPCommunityFixes.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@
164164
<Compile Include="Modding\ModUpgradePipeline.cs" />
165165
<Compile Include="Performance\CraftBrowserOptimisations.cs" />
166166
<Compile Include="Modding\BaseFieldListUseFieldHost.cs" />
167+
<Compile Include="Performance\ExpansionBundlePreload.cs" />
167168
<Compile Include="Performance\FasterEditorPartList.cs" />
168169
<Compile Include="Performance\ForceSyncSceneSwitch.cs" />
169170
<Compile Include="Performance\AsteroidAndCometDrillCache.cs" />

0 commit comments

Comments
 (0)