Interanlly Cache value so looping continously isn't costly. Only assign physicalCoreCount when needed.

This commit is contained in:
sunshineinabox 2023-07-08 07:45:09 -07:00
parent f4dbfe890a
commit b5cb5c83fa

View file

@ -16,6 +16,7 @@ namespace Ryujinx.Common.SystemInfo
public ulong RamTotal { get; protected set; } public ulong RamTotal { get; protected set; }
public ulong RamAvailable { get; protected set; } public ulong RamAvailable { get; protected set; }
protected static int LogicalCoreCount => Environment.ProcessorCount; protected static int LogicalCoreCount => Environment.ProcessorCount;
private static int? _cachedPhysicalCoreCount = null;
protected SystemInfo() protected SystemInfo()
{ {
@ -80,6 +81,11 @@ namespace Ryujinx.Common.SystemInfo
public static int GetPhysicalCoreCount() public static int GetPhysicalCoreCount()
{ {
if (_cachedPhysicalCoreCount.HasValue)
{
return _cachedPhysicalCoreCount.Value;
}
int coreCount = Environment.ProcessorCount; int coreCount = Environment.ProcessorCount;
try try
@ -128,6 +134,8 @@ namespace Ryujinx.Common.SystemInfo
Logger.Error?.Print(LogClass.Application,$"An error occurred while trying to get the physical core count: {ex.Message}"); Logger.Error?.Print(LogClass.Application,$"An error occurred while trying to get the physical core count: {ex.Message}");
} }
_cachedPhysicalCoreCount = coreCount;
return coreCount; return coreCount;
} }
} }