Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loader performance optimization #108

Closed
gotmachine opened this issue Dec 31, 2022 · 0 comments
Closed

Loader performance optimization #108

gotmachine opened this issue Dec 31, 2022 · 0 comments
Labels
kspPerformance Possible performance improvement in KSP

Comments

@gotmachine
Copy link
Contributor

The KSP loader has a long standing issue where a lot of small atomic operations are done in frame-yielding coroutines.
Extensive texting show that the overhead of having to render a frame in-between each atomic operation is quite tiny, less than 1%.

However, this start to matter a lot more if framerate is capped. KSP ensure that no limit is active on its side, but it can't do anything about GPU driver enforced limits (VSync, adaptive sync, whatever...), which is a relatively common scenario nowadays. With a 60 FPS limit in place, loading can easily take 3 times longer than in an unlimited framerate scenario.

Aside from that, asset loading can be made significantly faster by pulling the data from disk to memory in a separate thread and queuing the in-memory data for being processed continuously in the main thread.

The FastLoader KSPCF patch is a complete reimplementation of the core KSP loader :

  • Removal of framerate dependency in asset loading and part compilation stages.
  • Parallel async loading of audio assets
  • A worker thread is used to pull texture and model asset from disk to memory, putting them in a buffer to be consumed by the main thread. Also implement a byte array pool to reduce GC allocations.
  • Various small optimizations to the individual main thread asset loaders, mainly in the PNG loader (faster parsing, faster swizzle algorithm for normal maps)
  • Caching of PNG textures as raw DXT5 compressed data (reimplementation of the TextureLoaderOptimization patch)

Overall, this gives a 20 to 50% bump in asset loading speed depending on hardware specs, which depending on installed mods gives a 15-30% total loading time improvement.

@gotmachine gotmachine added the kspPerformance Possible performance improvement in KSP label Dec 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kspPerformance Possible performance improvement in KSP
Development

No branches or pull requests

1 participant