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

That is roughly 65% of my total compilation and domain reload time.
What
The
Hell?


This is with the latest version 1.19.19

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.

/// <summary>
        /// Refresh values in the global profile variables table.
        /// </summary>
        public async void RefreshGlobalProfileVariables()
        {
            var vars = GlobalProfileVariables;
            vars.Clear();

            var ipAddressList = await Task.Run(() => GetIpAddresses());

            if (ipAddressList.Count > 0)
            {
                vars.Add(KPrivateIpAddressKey, ipAddressList[0].ToString());

                if (ipAddressList.Count > 1)
                {
                    for (var i = 1; i < ipAddressList.Count; i++)
                        vars.Add(KPrivateIpAddressKey + "_" + i, ipAddressList[i].ToString());
                }
            }
        }

        private List<IPAddress> GetIpAddresses()
        {
            var ipAddressList = FilterValidIPAddresses(NetworkInterface.GetAllNetworkInterfaces()
                .Where(n => n.NetworkInterfaceType != NetworkInterfaceType.Loopback && n.OperationalStatus == OperationalStatus.Up)
                .SelectMany(n => n.GetIPProperties().UnicastAddresses)
                .Where(a => a.Address.AddressFamily == AddressFamily.InterNetwork)
                .Select(a => a.Address).ToList());

            return ipAddressList;
        }
4 Likes

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.

Hi all thanks for posting! We’ve recently received a support ticket for this same issue. Will fix this in a future release

4 Likes

@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?

Hi @TheAnyKey unfortunately the ticket is still in our to-do bucket. Here’s the public tracker link Unity Issue Tracker - Method RefreshGlobalProfileVariables is executed when script compilation occurs

@pillakirsten Thanks for the public tracker link! I just gave it an upvote!

1 Like

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;
}

Hi @jjeffery thanks for the suggestion! Coincidentally we’ve received a feature request to do exactly this. Will be implemented in future release