You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
During the development of our current game we noticed that the LateUpdate method of SteamAudioManger 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 cs mCurrentScene.Commit() in it's own method CommitScene() inside SteamAudioManager and then called that method in the relevant places of SteamAudioDynamicObject and SteamAudioStaticMesh
Additionally a transform.hasChanged was added to SteamAudioDynamicObject 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 and LateUpdate now takes between 0.1ms and 0.3ms on average
Kulgann
changed the title
Perormance optimizations concerning calling mCurrentScene.Commit(); in LateUpdate
[Unity] Perormance optimizations concerning calling mCurrentScene.Commit(); in LateUpdate
Oct 27, 2023
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.
@Kulgann No problem! Thanks for investigating the issue and putting together the initial fix.
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
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.
Description
During the development of our current game we noticed that the
LateUpdatemethod ofSteamAudioMangerwas 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

cs mCurrentScene.Commit()in it's own methodCommitScene()insideSteamAudioManagerand then called that method in the relevant places ofSteamAudioDynamicObjectandSteamAudioStaticMeshAdditionally a
transform.hasChangedwas added toSteamAudioDynamicObjectso 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 and
LateUpdatenow takes between 0.1ms and 0.3ms on average