Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question 2022 Performance - FMOD Audibility Computation

Discussion in 'Audio & Video' started by leea1, Jun 8, 2023.

  1. leea1

    leea1

    Joined:
    May 13, 2020
    Posts:
    11
    Hi all,

    Since the 2022 LTS was released, I've been doing a test upgrade of our project. Our project used to run with a framerate in the hundreds (2021 LTS) but is now in the teens (any 2022 version). Running the profiler, shows that the majority of this is in the Audio.FMODSystemUpdate > Audibility computation.

    2022-audio-profiler.png

    Our project has a rather large number of AudioSources (2K+) added at startup/runtime from about 400 AudioClips, but very few, if any, are playing at any given time. In fact, I had zero playing and performance was still abysmal. In any case, 2021 was fine...

    Does anyone know what changed in the 2022 versions that could cause this? General thoughts/comments welcome as well...

    Thanks!
     
    Unifikation likes this.
  2. Evgeno

    Evgeno

    Joined:
    Sep 8, 2014
    Posts:
    56
    Also interested in this issue
     
  3. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,073
    +1 What's going on here?
     
  4. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    4,865
    Make a bug report with both 2021 and 2022 versions attatched so it can be fixed
     
  5. leea1

    leea1

    Joined:
    May 13, 2020
    Posts:
    11
    I wasn't sure if this was actually a bug or something we simply missed, so I wanted to gather more info first.

    Found a workaround... disabling all AudioSources then re-enabling them all seems to address our issues, at least initially at startup (I'd expect actually playing a large number of sounds would eventually reduce performance).

    It does seem like a bug since simply disabling/enabling AudioSource corrects, will work on another bug report *sigh*...

    Aside from not playing, does anyone know what disabling does?
     
    DevDunk likes this.
  6. rafaelmfernandez

    rafaelmfernandez

    Joined:
    Aug 11, 2013
    Posts:
    62
    Same issue here. Its only about 2ms for me but still significant issue.
     
  7. leea1

    leea1

    Joined:
    May 13, 2020
    Posts:
    11
    For those curious, this was categorized as a regression, but "by design"...
    https://issuetracker.unity3d.com/issues/performance-drops-when-using-a-lot-of-audio-sources

    Though I'm not sure my report got transcribed correctly between bug report and issue ticket. i.e. you don't have to be playing any of the sounds to lose performance and various cases that have AudioSources in the same state result in some working and some not...
    • AudioSources attached/enabled to scene before playing = ok
    • AudioSources attached/enabled in "Start" = bad
    • AudioSources attached/enabled in "Start" then toggle disabled/enabled = ok
    • Regardless of how attached, playing an AudioSource (that completes and doesn't loop) = incrementally bad (leaks performance)
     
    Last edited: Aug 10, 2023
    inferno222 likes this.
  8. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,073
    Did they say why unused AudioSources were designed to be a slowdown?

    I'm doing much the same as you, huge pools of AudioSources.
     
  9. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    I ran into this issue in my game too. It's so weird and it just tank my fps... I don't understand why they would make such a impactful change in an LTS version?
     
  10. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Can you share a bit more how you made this work? I have tried disable/enable all mine, both gameobject and audiosource component and it have no impact on the performance, the profile keeps telling be it use way to much time on this Fmod audio thingy. Really annoying.
     
  11. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,571
    Responding to hear any updates. Very concerning that Unity has pretty much destroyed the audio system for a significant number of users with this (they probably thought innocuous) change. Sigh....
     
    Last edited: Nov 24, 2023
    Unifikation likes this.
  12. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    379
    Hi everyone,

    I posted this internally to see if I can gather more feedback on this matter. I'll let you know what I learn. Just know that we're doing our best, and that the way all this is intertwined we happen to miss certain side-effects. We do have wide safety net of tests on multiple levels and we catch a lot of these in our process, but not all of them sadly...

    Thank you for the feedback!
     
    Peter77 and DevDunk like this.
  13. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Yeah it make sense you need to move the engine forward to make it better, we just need to have a way to follow alone with out rebuilding our entire games.

    I'm sure this is not something you are going to rollback, however, if you could provide some alternative way of doing it or a work-around or something, until you get to the part that actually makes this perform good again.

    As I remember from the MasterAudio documentation, I'm pretty sure they stated that an inactive AudioSource was almost free, therefore their entire system it build around that assumption, which is apparently no longer the case.

    However, I must say, I still see what appears to be a bit random behavior - or else I just haven't figured out what actually triggers it. Because in my latest build, yes I upgraded to 2022.3.14 and rebuild the Library/cache (just in case) and now I get decent performace with 45.000 AudioSources.

    Anyway, looking in the profiler, it's pretty obvious that this LatePostUpdate.UpdateAudio is the number 1 or 2 most tasking part of my frames, even with no sounds playing at all.
    So it seems very odd.
     
  14. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    By the way, if you have the right access, can you please delete these stupid spam comments on the ticket:
    https://issuetracker.unity3d.com/issues/performance-drops-when-using-a-lot-of-audio-sources
     
  15. Niiisss

    Niiisss

    Unity Technologies

    Joined:
    Sep 1, 2022
    Posts:
    2
    Hi, I can verify that we're aware of the issue and working on a fix that will be back-ported to all LTS versions.
     
    maxiboch, DevDunk and Laumania like this.
  16. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    379
    Ugh that's ugly... I can't do that myself but I'll definitely flag it'

    ***

    It appears that my Danish colleagues are actually onto this and actively working on this! We're gathering soon to discuss that refactor.

    I think you already know it, but for anyone else reading this:

    The audio developers of Unity are as much part of this community as you guys are.

    I've never seen an audio dev working just to pay the bills. We are as frustrated as you are, if not more, when issues like that arise, because we care. We love the depth of the science, understand the weight it has on a game production and admire the effect of well crafted sound design.

    Unity Editor/Engine is an incredibly ambitious project considering its scope. Many game developer companies working with other editors/engines are using a myriad of different tools to ship a game, while Unity does embed a lot of that complexity. This means that changing anything in there comes with incredible inertia, and leads to this kind of event.

    We're super grateful when you can surface this kind of workaroundable-but-painful bugs. We're working on them, and we'll get them all eventually :cool: because we're proud to work on a product that has such a high impact in a field we love.

    Cheers!
    Vincent
     
    MartinTilo and Laumania like this.
  17. Niiisss

    Niiisss

    Unity Technologies

    Joined:
    Sep 1, 2022
    Posts:
    2
    The reason that the audibility computations are so slow is that we at some point redesigned the algorithm that computes the audibility of each audio node. The runtime complexity for the new algorithm unfortunately blows up for big graphs with thousands of nodes. We've found the root cause for the slow-down and have redesigned the algorithm so that it is much faster (500x speedup for a graph with 3000 nodes).
     
    maxiboch, Laumania and SeventhString like this.
  18. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Thas is very nice! Thanks for quick response!
     
  19. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    I understand and as stated, I totally understand and want you to move the engine forward, as I intend to use it for many years to come :D

    Great to get responses like this - we hope for the best :)
     
  20. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Uhhh exciting! Also a fix that can get into current LTS? :D
     
  21. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    By the way, please test it with 50.000 AudioSources too - of cause with 99% of them being inactive. :)
     
  22. Unifikation

    Unifikation

    Joined:
    Jan 4, 2023
    Posts:
    1,073
    You use FMOD... a VERY old version that you've not bothered to update the licensing terms of with the company that makes FMOD... hence the many internal bandaids and bodge ups.

    We all know this.

    They (FMOD) know this. They compromised as much as they could and provided a free, more recent version, to the Asset Store.

    All that IPO money and you still couldn't license a newer version of FMOD?
     
  23. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Do I dare to ask if you have an ETA on this? :)

    By the way I have done some more digging and from what I found, it's not the actual amount of AudioSources that makes it go bbbrrrr, it's the amount of distinct audioclips on these audiosources.


    Code (CSharp):
    1. [Command("fm-debug-audiosourcecount")]
    2. public static void AudioSourceCount()
    3. {
    4.     var foundAudioSources  = GameObject.FindObjectsOfType<AudioSource>(true);
    5.     var distinctAudioClips = foundAudioSources.DistinctBy(x => x.clip);
    6.     Debug.Log($"Currently {foundAudioSources.Length} AudioSources in the hierarchy (both enabled and disabled) with {distinctAudioClips.Count()} distinct audioclips");
    7. }

    Screenshot_202.png Screenshot_201.png
     
  24. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,512
    If you care about audio, you picked the wrong company to work for.
     
  25. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,571
    It would be great if the PostLateUpdate.UpdateAudio() step could be optimized and also moved off the main thread.
     
  26. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Peter77 likes this.
  27. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    379
    I hear you... while audio in Unity might sometime feel like a pothole on the road of game development, having the opportunity to fix it is motivating. Also, the additional challenge of having an audio stack within a game engine is thrilling, in terms of pure C++ and computer science, it's a super cool context to learn and evolve in. For me it's more about the travel than the destination to be honest.
     
    laurentlavigne and AcidArrow like this.
  28. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Any ETA on this?

    My game gets hit BIG TIME big this bug... and it seems to get worse overtime eventhough the amount of audiosources/audioclips doesn't change during gameplay. :(
     
    Unifikation likes this.
  29. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Just to add a bit more to how much this impacts a game with many sounds.
    This is my game in Unity 2021.3.22f1
    Screenshot_203.png

    And this is how it is in Unity 2022.3.14
    Screenshot_201.png

    The difference is HUGE and it takes the FPS in half or more :(

    Please fix this asap.
     
  30. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Sorry for asking again, but this bug is really destroying my game with like 50% fps and decreasing overtime it seems...

    When can I see it fixed in 2022.3.x LTS? Just an ETA.
     
  31. SeventhString

    SeventhString

    Unity Technologies

    Joined:
    Jan 12, 2023
    Posts:
    379
    We are not able to provide reliable ETA for fixes sorry. The approval and backporting process is efficient, but still takes some time. Hopefully it can be approved and submitted on our trunk this month, then it will certainly be merged on the LTS branches, but that's handled by another team.

    I think it's possible it gets to you early 2024, but there is no way to provide a solid date.
     
    Laumania and Peter77 like this.
  32. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Ok, thanks for responding anyway. I understand you cannot say exactly when its out, but thanks for coming with a qualified guess.
    As long as this gets fixed I'm happy!

    I would have preferred it fixed before New Years as my game is all about fireworks and I just published a multiplayer beta so people can play together...and this bug is just eating peoples FPS like there's no tomorrow.
     
  33. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Is there a issue tracker on this particular fix/issue that I can keep an eye on to follow along?

    Because the issue mentioned earlier in this thread is not the one I hope, as it's closed with a "By Design" resolution...which cannot be correct.
    https://issuetracker.unity3d.com/issues/performance-drops-when-using-a-lot-of-audio-sources
     
  34. maxiboch

    maxiboch

    Joined:
    Jan 13, 2015
    Posts:
    7
    @Laumania totally feel yr pain.

    we've been able to work around the issue with the following steps:

    -move audiosources into an object pool, one sized just larger than the max number of simultaneous voices
    -adjust virtual voice count so it's larger than the count of the audiosources in the pool
    -initialize all the sources in the pool on awake by disabling, enabling, adding a clip, and finally playing & stoping each source
     
    laurentlavigne likes this.
  35. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Oh thanks, however, I'm using MasterAudio so I'm limited in what I can actually do, so @jerotas need to tip in here, as he made MasterAudio.
     
    jerotas likes this.
  36. jerotas

    jerotas

    Joined:
    Sep 4, 2011
    Posts:
    5,571
    Sounds like @Laumania has fixed his custom script on his end. He PM'd me.
     
    SeventhString likes this.
  37. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    Yes, at least in my case I managed to get it to work with MasterAudio.

    I first tried just disable/enable all AudioSources in the hierarhcy, but that didn't work for some reason.

    I'm loading the majority of my audio dynamically as they are coming from mods. By trial/error I found out that is I disabled and enabled the SoundGroup (MasterAudio component) BEFORE it's getting created via the DynamicSoundGroupCreator (or what ever it's called) it suddently worked!!

    So these two lines gave my game 100+% FPS than before :)
    soundGroup.gameObject.SetActive(false);
    soundGroup.gameObject.SetActive(true);

    When that said, yes it makes it work, however, I already have some indications from players that it might be getting worse again over a game session. I havent profiled it yet, it's just to say I still need that Unity fix :)

    Here how it looked without the fix:
    Screenshot_224.png


    And after these two lines:
    Screenshot_227.png

    It's a CRAZY improvement - meaning it's a crazy bug and why it should be fixed asap :)
     
    SeventhString likes this.
  38. ODINKONG

    ODINKONG

    Joined:
    Nov 4, 2014
    Posts:
    112
    +1 to this being the biggest drag on our frame rate at the moment (Unity 2022.3.8) Is it worth updating yet?
    upload_2023-12-19_18-56-49.png
     
  39. Lertulo

    Lertulo

    Joined:
    Jul 12, 2014
    Posts:
    5
    This thread helped me a lot when I hit this problem. My mistake was thinking that an AudioSource, once produced and set to playing in a non-looping mode, was somehow going to automatically destroy itself when its last reference went away. That's not the case, which is obvious in retrospect. So if you're like me and you were playing each sound effect by fabricating a new AudioSource and setting it to play once, your performance is going to tank over time; manage the lifecycle of your audio sources better, and this problem will go away for you.
     
  40. leea1

    leea1

    Joined:
    May 13, 2020
    Posts:
    11
    I sorta lost track of this after the initial ticket response. Sorry, if I didn't respond to anyone. Glad this got picked back up. Thanks everyone who was more persistent than I.
     
  41. Laumania

    Laumania

    Joined:
    Jun 27, 2012
    Posts:
    221
    SeventhString likes this.