Search Unity

Audio Fixed a huge performance issue with Wwise in editor.

Discussion in 'Audio & Video' started by gsylvain, May 15, 2020.

  1. gsylvain

    gsylvain

    Joined:
    Aug 6, 2014
    Posts:
    104
    edit: Wwise version 2019.2.0.7216

    Over the past weeks, we added a ton of new sound banks in our project. We noticed that the game performance was going down. Using unity profiler and wwise profiler did not show anything bad.. Today, I had a flash and decided to profile the Editor itself and * oh my god *. I was just there. A massive CPU load, every frame. Why? Wwise! The good thing is that it is really easy and fast to fix it.

    1. AkBasePathGetter.cs, method GetPlatformBasePathEditor
    The *editor* method was literally loading the config file from disk and instantiating a new WwiseSettings class every * single * frames. The fun thing is that the AkWwiseEditorSettings has a method that create the config only once, much more faster! Why isn't this the default way?!
    Code (CSharp):
    1. // var Settings = WwiseSettings.LoadSettings();
    2. var Settings = AkWwiseEditorSettings.Instance;
    2. AkBasePathGetter.cs,method GetPlatformBasePathEditor
    The DirectoryInfo.GetFiles call is SUPER heavy... Once the wwise setup has been validated, it is pretty permanent, right? So I decided to comment the second try/catch (the one that contain "var foundBanks = di.GetFiles(.....". I simply return SoundBankDest; no matter what.

    Code (CSharp):
    1.  
    2. return SoundBankDest;
    3. /*
    4. try
    5.         {
    6.             // Verify if there are banks in there
    7.             var di = new System.IO.DirectoryInfo(SoundBankDest);
    8.             var foundBanks = di.GetFiles("*.bnk", System.IO.SearchOption.AllDirectories);
    9.             if (foundBanks.Length == 0)
    10.             {
    11.                 return null;
    12.             }
    13.  
    14.             if (!SoundBankDest.Contains(platformName))
    15.             {
    16.                 if (LogWarnings)
    17.                     UnityEngine.Debug.LogWarning("WwiseUnity...");
    18.             }
    19.          
    20.             return SoundBankDest;
    21.         }
    22.         catch
    23.         {
    24.             return null;
    25.         }
    26. */
    3. AkWwiseXMLWatcher.cs, method OnEditorUpdate
    The call AkBasePathGetter.GetPlatformBasePath() is heavy. Simply cache it!
    Code (CSharp):
    1.     private string _platformBasePath = string.Empty;
    2.     private void OnEditorUpdate()
    3.     {
    4.         var logWarnings = AkBasePathGetter.LogWarnings;
    5.         AkBasePathGetter.LogWarnings = false;
    6.  
    7.         // Patching performance issue in-editor.
    8.         if (string.IsNullOrEmpty(_platformBasePath))
    9.             _platformBasePath = AkBasePathGetter.GetPlatformBasePath();
    10.    
    11.         AkBasePathGetter.LogWarnings = logWarnings;
    12.  
    13.         try
    14.         {
    15.             if (ExceptionOccurred || _platformBasePath != XmlWatcher.Path)
    16.                 XmlWatcher.Path = _platformBasePath;
    17.  
    18.             ExceptionOccurred = false;
    19.         }
    20.         catch
    21.         {
    22.             ExceptionOccurred = true;
    23.         }
    And voilà, the editor speed is now back to 100%
     
    Last edited: May 19, 2020