Skip to content

Parallelize FastLoader second config pass - #422

Open
tobiasnmf wants to merge 1 commit into
KSPModdingLibs:masterfrom
tobiasnmf:UrlDirRefreshParallel
Open

Parallelize FastLoader second config pass#422
tobiasnmf wants to merge 1 commit into
KSPModdingLibs:masterfrom
tobiasnmf:UrlDirRefreshParallel

Conversation

@tobiasnmf

Copy link
Copy Markdown
Contributor

This PR follows up #415 by parallelizing the refresh of existing GameData directories during FastLoader's second config pass.

A flat list of existing directories are iterated over with Parallel.For and refreshed similarly like it was before
It builds a flat list of the existing directories and refreshes them using Parallel.For. UrlDir and UrlFile ctor aren't thread safe and so are guarded by locking

It also replaces DirectoryInfo enumeration and FileInfo metadata reads with Directory.GetFileSystemEntries and MonoIO.GetFileStat, which are faster on KSP's Mono runtime, at least on my machine.

The refresh still detects files and directories added, removed, or modified by Startup.Instantly addons.

Modded profiles

Mods used when profiling
KSP version: 1.12.5.3190

Installed modules:

- ALCOR 1.0.1
+ ASETAgency v2.0.2
- ASETAvionics v3.0.1
+ ASETProps v2.0.7
- Astrogator v1.0.2
A Atmosphere (unmanaged)
- AvalanchePlumes v1.0.5.1
+ B9PartSwitch v2.21.0.4
- BackgroundResourceProcessing 0.3.2
A BreakingGround-DLC 1.7.1 (unmanaged)
A BuildManager (unmanaged)
- BurstPQS 0.1.24
A CelestialShadows (unmanaged)
- Chatterer 0.9.99
- ChattererExtended 0.6.2
A CityLights (unmanaged)
- ClickThroughBlocker 1:2.1.10.23
- CommunityCategoryKit v112.0.1
+ CommunityResourcePack v112.0.1
+ CommunityTechTree 1:3.4.5
- ContractConfigurator v2.13.3.0
- DE-IVAExtension v1.3.0
- Deferred 1.3.5.0
- DistantObject v2.2.1.7
+ DistantObject-default v2.2.1.7
- DockingPortAlignmentIndicator 6.13.1.0
- EasyVesselSwitch 2.3
- EditorExtensionsRedux 3.4.7
A EVEManager (unmanaged)
+ FilterExtensions 3.2.9.1
- FilterExtensionsDefaultConfig 3.2.9.1
- Firefly 1.0.6
+ FireflyAPI 1.0.0.0
- Firespitter v7.17
+ FirespitterCore v7.17
+ FirespitterResourcesConfig v7.17
- FreeIva 0.2.20.2
+ Harmony2 2.2.1.0
- HullcamVDSContinued 0.2.2.4
- JanitorsCloset 0.4.1.3
- KAS 1.12
- KerbalChangelog v1.4.2
- KerbalEngineerRedux 1.1.9.5
- KerbalFX-AeroFX 0.8.1
- KerbalFX-BlastFX 0.8.1
+ KerbalFX-Core 0.8.1
- KerbalFX-ImpactPuffs 0.8.1
- KerbalFX-RoverDust 0.8.1
- KIS 1.29
+ Konstruction v112.0.1
+ Kopernicus 2:release-1.12.1-247
- kOS 1:1.6.0.1
- kOS-Astrogator v0.2.2
- kOS-Career 0.3.0.0
- kOS-EVA 0.2.0.0
- kOS-KerbalEngineer v0.1.1
- kOS-MechJeb2 0.0.4
- kOS-SCANSat 1.2.0.0
- kOS-StockCamera 0.2.0.0
- kOSforAll 0.0.5
- kOSPropMonitor 1.7.3
- KSAIVAUpgrade v1.6.7
+ KSPBurst v1.7.4.11
+ KSPBurst-Lite v1.7.4.11
^ KSPCommunityFixes 1:1.41.1
+ KSPTextureLoader 1.0.35
A MakingHistory-DLC 1.12.1 (unmanaged)
- MechJeb2 2.15.3.0
- MK12PodIVAReplacementbyASET 1:v2.0.1
- Mk1LanderCanIVAReplbyASET v2.0.1
- MoarFEConfigs 1.0.5.2
+ ModularFlightIntegrator 1.2.10.0
+ ModuleManager 4.2.3
- NavUtilitiesUpdated 0.8.1.1
+ NearFutureProps 1:0.7.2
- ParallaxContinued 1.0.4
- ParallaxContinued-Lifeless-Eve-Patch 1.0.0
- ParallaxContinued-Planet-Textures 1.0.3
- ParallaxContinued-Scatter-Textures 1.0.3
- ParallaxContinued-Terrain-Textures 1.0.3
A PartFX (unmanaged)
- PlanetShine 0.2.6.6
+ PlanetShine-Config-Default 0.2.6.6
A PQSManager (unmanaged)
- ProbeControlRoomRecontrolled 1.4.0
- ProbesBeforeCrew 3.3.2
- QuickIVA 1:1.3.0.11
- QuickStart 1:2.2.1.5
- RasterPropMonitor 1:v1.1.0.1
+ RasterPropMonitor-Core 1:v1.1.0.1
- ReStock 1.5.1
- ReStockPlus 1.5.1
- RestockWaterfallExpansion 0.2.0
- Reviva 1.0.2
- RocketSoundEnhancement 0.9.13
+ RocketSoundEnhancement-Config-Default 1.3.1
- SCANsat v21.1
A Scatterer (unmanaged)
- ScienceAlert 1.9.20.5
+ Shabby 0.4.2
A ShaderLoader (unmanaged)
+ SmokeScreen 2.8.14.0
+ SpaceTuxLibrary 0.0.9
- StationPartsExpansionRedux 2.0.11
- StationPartsExpansionRedux-IVAs 2.0.11
- StockWaterfallEffects 0.8.0
A Terrain (unmanaged)
A TextureConfig (unmanaged)
- Toolbar 1:1.8.1.2
- ToolbarController 1:0.1.9.14
- TrackingStationEvolved 2:1.0.9.1
- Trajectories v2.4.5.4
- TransferWindowPlannerFork v1.9.1.1
- TriggerAu-Flags v2.11.0.0
- TUFX 1.1.1
- UKS 1:v112.0.1
+ USI-Core v112.0.1
+ USITools v112.0.1
A Utils (unmanaged)
- VaporCones 1.2.0
- VesselView 2:0.8.9
+ VesselView-UI-RasterPropMonitor 1:0.8.9
- VolumetricVaporCones 1.0.1
- Waterfall 0.11.0
- WaterfallRestock 0.2.3
- WaypointManager 2.8.4.7
- xScienceContinued 6.0.3.1

Before:

[LOG 17:02:50.111] [KSPCF:FastLoader] AMD Ryzen 9 5900X 12-Core Processor  | 32693 MB | NVIDIA GeForce RTX 5080 (15979 MB)
Total loading time to main menu : 58.232s
- Configs and assemblies loaded in 9.302s
- Configs reload done in 1.022s
- Configs translated in 0.086s
- 8727 assets loaded in 8.921s :
  - 1393 audio assets (312.77 MiB) in 7.437s, 42.057 MiB/s
  - 4442 texture assets (2.461 GiB) in 0.526s, 4.676 GiB/s
  - 2874 model assets (437.884 MiB) in 0.942s, 464.829 MiB/s
- Asset bundles loaded in 0.314s
- GameDatabase (configs, resources, traits, upgrades...) loaded in 0.261s
- Built-in parts copied in 0.020s
- Part and internal configs extracted in 0.007s
- 1096 parts and 11617 modules compiled in 7.057s
  - 10.6 modules/part, 6.438 ms/part, 0.607 ms/module
  - PartIcon compilation : 2.224s
- 199 internal spaces and 1632 props compiled in 4.780s
- 2 DLC (Making History, Breaking Ground) loaded in 0.431s
- Planetary system loaded in 7.194s

After:

[LOG 16:54:39.846] [KSPCF:FastLoader] AMD Ryzen 9 5900X 12-Core Processor  | 32693 MB | NVIDIA GeForce RTX 5080 (15979 MB)
Total loading time to main menu : 56.611s
- Configs and assemblies loaded in 9.059s
- Configs reload done in 0.143s
- Configs translated in 0.091s
- 8727 assets loaded in 8.922s :
  - 1393 audio assets (312.77 MiB) in 7.394s, 42.303 MiB/s
  - 4442 texture assets (2.461 GiB) in 0.538s, 4.576 GiB/s
  - 2874 model assets (437.884 MiB) in 0.979s, 447.265 MiB/s
- Asset bundles loaded in 0.375s
- GameDatabase (configs, resources, traits, upgrades...) loaded in 0.261s
- Built-in parts copied in 0.019s
- Part and internal configs extracted in 0.005s
- 1096 parts and 11617 modules compiled in 6.877s
  - 10.6 modules/part, 6.275 ms/part, 0.592 ms/module
  - PartIcon compilation : 2.178s
- 199 internal spaces and 1632 props compiled in 4.622s
- 2 DLC (Making History, Breaking Ground) loaded in 0.433s
- Planetary system loaded in 7.455s

- Parallel.For over all directories instead of recursive
- Faster file IO functions

@Phantomical Phantomical left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be a little bit before I'm home and have time to land KSPCF PRs, but this LGTM.

Comment on lines +800 to +801
// Not safe to create UrlFile on multiple threads
private static readonly object urlCreationLock = new object();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this is only because the ConfigNodePerf patch uses static buffers instead of thread-local ones. It should be pretty easily fixable as a follow-up.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have done this on a separate branch now. Do you want this as part of this PR, or should I wait until this PR is merged?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whichever is easier for you. I am fine with it being done in this PR

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