Parallelize FastLoader second config pass - #422
Open
tobiasnmf wants to merge 1 commit into
Open
Conversation
- Parallel.For over all directories instead of recursive - Faster file IO functions
Phantomical
approved these changes
Aug 13, 2026
Phantomical
left a comment
Collaborator
There was a problem hiding this comment.
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(); |
Collaborator
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
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?
Collaborator
There was a problem hiding this comment.
Whichever is easier for you. I am fine with it being done in this PR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR follows up #415 by parallelizing the refresh of existing
GameDatadirectories during FastLoader's second config pass.A flat list of existing directories are iterated over with
Parallel.Forand refreshed similarly like it was beforeIt builds a flat list of the existing directories and refreshes them using
Parallel.For.UrlDirandUrlFilector aren't thread safe and so are guarded by lockingIt also replaces
DirectoryInfoenumeration andFileInfometadata reads withDirectory.GetFileSystemEntriesandMonoIO.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.Instantlyaddons.Modded profiles
Mods used when profiling
Before:
After: