From 73feac5819903bbc16ebb3b4a47b5734d5699492 Mon Sep 17 00:00:00 2001 From: Jumpman <41526355+JumpmanSr@users.noreply.github.com> Date: Mon, 14 Mar 2022 22:49:35 -0400 Subject: [PATCH] Caching local network info and using an event handler to invalidate as needed (improves menu slow down issue in FE3H) (#2761) * Update IGeneralService.cs Fix IPV4 local ip related frame drop in fire emblem by rewriting [CommandHipc(12)] * Fix IPV4 Local IP Slowdown & Style Fixes fix a missing space * Remove unnecessary line * Fix for hardcoding which index to use * Replace argument with empty string. By sending an empty string to Dns.GetHostAddresses("") you get back localhost info only. * Add caching, undo change in GetCurrentIpAddress Implement caching and revert the GetCurrentIP() function, speed improvements still present. * Remove unnecessary using * Syntax fixes and removing extra lines Requested changes by AcK77 * Properly unsubscribe from event handler Adds an unsubscribe in the dispose section of IGeneralService --- .../Nifm/StaticService/IGeneralService.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs b/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs index 2296838e..ba91f08c 100644 --- a/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs +++ b/Ryujinx.HLE/HOS/Services/Nifm/StaticService/IGeneralService.cs @@ -14,6 +14,9 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService { private GeneralServiceDetail _generalServiceDetail; + private IPInterfaceProperties _targetPropertiesCache = null; + private UnicastIPAddressInformation _targetAddressInfoCache = null; + public IGeneralService() { _generalServiceDetail = new GeneralServiceDetail @@ -22,6 +25,8 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService IsAnyInternetRequestAccepted = true // NOTE: Why not accept any internet request? }; + NetworkChange.NetworkAddressChanged += new NetworkAddressChangedEventHandler(LocalInterfaceCacheHandler); + GeneralServiceManager.Add(_generalServiceDetail); } @@ -165,6 +170,11 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService return (null, null); } + if (_targetPropertiesCache != null && _targetAddressInfoCache != null) + { + return (_targetPropertiesCache, _targetAddressInfoCache); + } + IPInterfaceProperties targetProperties = null; UnicastIPAddressInformation targetAddressInfo = null; @@ -194,13 +204,26 @@ namespace Ryujinx.HLE.HOS.Services.Nifm.StaticService } } + _targetPropertiesCache = targetProperties; + _targetAddressInfoCache = targetAddressInfo; + return (targetProperties, targetAddressInfo); } + private void LocalInterfaceCacheHandler(object sender, EventArgs e) + { + Logger.Info?.Print(LogClass.ServiceNifm, $"NetworkAddress changed, invalidating cached data."); + + _targetPropertiesCache = null; + _targetAddressInfoCache = null; + } + protected override void Dispose(bool isDisposing) { if (isDisposing) { + NetworkChange.NetworkAddressChanged -= LocalInterfaceCacheHandler; + GeneralServiceManager.Remove(_generalServiceDetail.ClientId); } }