Skip to content

ShipEffects: cache SoundLayerGroups globally instead of parsing per-vessel#53

Closed
bimo1d wants to merge 1 commit intoKSPModStewards:masterfrom
bimo1d:fix-shipeffects-soundlayer-cache
Closed

ShipEffects: cache SoundLayerGroups globally instead of parsing per-vessel#53
bimo1d wants to merge 1 commit intoKSPModStewards:masterfrom
bimo1d:fix-shipeffects-soundlayer-cache

Conversation

@bimo1d
Copy link
Copy Markdown
Contributor

@bimo1d bimo1d commented May 7, 2026

Hi again, follow-up to the debris-skip PR.

After debris are filtered out, the remaining hitch on separations comes from non-debris vessels. Profiler shows ~120ms in ShipEffects.Initialize, of which ~117ms is the SoundLayer parsing loop.

ShipEffectsConfig is global, AudioClips from GameDatabase are immutable, so the SoundLayer objects produced by CreateSoundLayerGroup are identical for every vessel. Parsing them once per vessel is pure overhead.

This PR moves the parsing into a lazy static cache (GetCachedSoundLayerGroups). Each vessel's Initialize copies references from the cache instead of re-parsing. SoundLayer instances are shared across vessels, but the per-vessel SoundLayerGroups dictionary owns it's own list copies to preserve existing per‑vessel isolation.

Thanks!

{A575C54C-32B6-47E1-A2B1-92A14F372278}

@JonnyOThan
Copy link
Copy Markdown
Member

Thanks for this; I implemented it a slightly different way but this is a great idea!

@JonnyOThan JonnyOThan closed this May 8, 2026
@bimo1d bimo1d deleted the fix-shipeffects-soundlayer-cache branch May 8, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants