[Unity] Improve perfomance in FMOD + Steam Audio #387
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.
Improve perfomance by reducing memory allocations per frame and GC pressure when using FMOD engine.
In an scene test of mine, I had 158 SteamAudioSources. Without this commit, SteamAudioSource.Update() took 3.77 ms per frame (7.2% of CPU budget) and allocated 137 kb per frame. After this commit, it took 2.8 ms per frame (5.8%) and allocates 79.8 kb per frame. That is a ~25% perfomance improvement in CPU and ~41% less of garbage for the GC.
For further improvement reflection should be eliminated (not shown in this commit). With my own tests I figured out it can reduce time to 0.17 ms (0.3%) and no garbage, equivalent to ~95% perfomance improvement. I did this by creating a new script without reflection (I can pass if you want) and then instantiating it with reflection (so reflection is only using at creation rather per update). However this script is outside Steam Audio library which is why it can have a reference to both Steam Audio and FMOD content. How to do this inside Steam Audio remains as a question...