Closed Kulgann closed 6 months ago
This is a good catch, and overall a good fix, thanks!
However, this solution is not thread-safe. iplSceneCommit
should not be called concurrently with any simulation functions. This is why SimulationManager.LateUpdate
only calls mCurrentScene.Commit()
when the simulation thread is in the WaitSleepJoin
state.
I think a simple change would be that instead of creating a SteamAudioManager.CommitScene
method that commits the scene right away, create a SteamAudioManager.MarkSceneDirty
(or similar) method, which just sets a flag indicating that the next LateUpdate
should commit the scene if the simulation thread is in WaitSleepJoin
state. This flag would then be cleared after the scene is actually committed. This way, the commit will only happen if a static mesh is added or removed, or if a dynamic object is added, removed, or has its transform updated.
Thank you for finishing this and I’m sorry nobody from our side managed to get to it.
@Kulgann No problem! Thanks for investigating the issue and putting together the initial fix.
Description
During the development of our current game we noticed that the
LateUpdate
method ofSteamAudioManger
was producing lag spikes of up to 60ms. See screenshot bellow:What we did was deep profile and establish that the culprit was the regular call to
mCurrentScene.Commit()
What we did
We isolated the call to![ScreenshotSteamAudioNoLagSpike](https://github.com/ValveSoftware/steam-audio/assets/4999276/48a43df3-5212-4db0-9869-244e6ac4c511)
cs mCurrentScene.Commit()
in it's own methodCommitScene()
insideSteamAudioManager
and then called that method in the relevant places ofSteamAudioDynamicObject
andSteamAudioStaticMesh
Additionally atransform.hasChanged
was added toSteamAudioDynamicObject
so that changes are only committed if the object has moved this frame. After this change we did not notice the introduction of any bugs or discrepancies in how the audio was played, but the lag spikes were gone andLateUpdate
now takes between 0.1ms and 0.3ms on average