Search Unity

Bug AddressableAssetSettings.OnEnable() adds 15 seconds domain reload time on every script compilation.

Discussion in 'Addressables' started by TheVirtualMunk, Mar 7, 2022.

  1. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    150
    That is roughly 65% of my total compilation and domain reload time.
    What
    The
    Hell?
    upload_2022-3-7_18-33-46.png
    This is with the latest version 1.19.19
     
  2. TheVirtualMunk

    TheVirtualMunk

    Joined:
    Sep 6, 2019
    Posts:
    150
    Digged a bit deeper after being annoyed for too long and found the culprit; NetworkInterface.GetAllNetworkInterfaces() in HostingServicesManager.
    Made it Async and boom, halved my compilation time.

    Unity please fix.

    Code (CSharp):
    1. /// <summary>
    2.         /// Refresh values in the global profile variables table.
    3.         /// </summary>
    4.         public async void RefreshGlobalProfileVariables()
    5.         {
    6.             var vars = GlobalProfileVariables;
    7.             vars.Clear();
    8.  
    9.             var ipAddressList = await Task.Run(() => GetIpAddresses());
    10.  
    11.             if (ipAddressList.Count > 0)
    12.             {
    13.                 vars.Add(KPrivateIpAddressKey, ipAddressList[0].ToString());
    14.  
    15.                 if (ipAddressList.Count > 1)
    16.                 {
    17.                     for (var i = 1; i < ipAddressList.Count; i++)
    18.                         vars.Add(KPrivateIpAddressKey + "_" + i, ipAddressList[i].ToString());
    19.                 }
    20.             }
    21.         }
    22.  
    23.         private List<IPAddress> GetIpAddresses()
    24.         {
    25.             var ipAddressList = FilterValidIPAddresses(NetworkInterface.GetAllNetworkInterfaces()
    26.                 .Where(n => n.NetworkInterfaceType != NetworkInterfaceType.Loopback && n.OperationalStatus == OperationalStatus.Up)
    27.                 .SelectMany(n => n.GetIPProperties().UnicastAddresses)
    28.                 .Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork)
    29.                 .Select(a => a.Address).ToList());
    30.  
    31.             return ipAddressList;
    32.         }
     
  3. wheee09

    wheee09

    Joined:
    May 21, 2018
    Posts:
    68
    I noticed that this became a problem when my VPN was turned on.

    Why is this even happening during a recompilation? Whatever info it is retrieving should be cached.
     
  4. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Hi all thanks for posting! We've recently received a support ticket for this same issue. Will fix this in a future release
     
  5. TheAnyKey

    TheAnyKey

    Joined:
    Feb 4, 2019
    Posts:
    2
    @pillakirsten Thanks for confirming that a fix is on the way! This issue is affecting one of my projects too. Any estimate of how soon the future release will be coming out?
     
  6. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
  7. TheAnyKey

    TheAnyKey

    Joined:
    Feb 4, 2019
    Posts:
    2
    @pillakirsten Thanks for the public tracker link! I just gave it an upvote!
     
    pillakirsten likes this.
  8. jjeffery

    jjeffery

    Joined:
    Jun 14, 2018
    Posts:
    1
    Incase it helps i dug into this for our project. The main pain point here is that addressables does an iteration through all network adapters and attempts a ping to find what is valid and what isn't, every single time you do a domain reload. The pain is that the timeout is 5 seconds! This time can easily be fixed by simply reducing the timeout to something more reasonable like 1 second. That or just cache the values and don't redo the work if the IPs are the same. ; )


    private List<IPAddress> FilterValidIPAddresses(List<IPAddress> ipAddresses)
    {
    List<IPAddress> validIpList = new List<IPAddress>();

    foreach (IPAddress address in ipAddresses)
    {
    var sender = new System.Net.NetworkInformation.Ping();
    var reply = sender.Send(address.ToString(), 5000);
    if (reply.Status == IPStatus.Success)
    {
    validIpList.Add(address);
    }
    }
    return validIpList;
    }
     
  9. pillakirsten

    pillakirsten

    Unity Technologies

    Joined:
    May 22, 2019
    Posts:
    346
    Hi @jjeffery thanks for the suggestion! Coincidentally we've received a feature request to do exactly this. Will be implemented in future release