Memory changes 3

General memory improvements to decrease GC pressure and frequency.

Pool big arrays and objects that are created and deleted often.

Skip data copies when they aren't needed.

Inline flag checks to skip unneeded allocations.

From my testing the performance is about the same, but the GC frequency is much lower and collection is faster causing less and smaller spikes.
This commit is contained in:
LotP
2025-11-23 13:43:14 -06:00
committed by KeatonTheBot
parent c1e24961f9
commit 35bced8527
42 changed files with 703 additions and 331 deletions
+10 -4
View File
@@ -1,5 +1,6 @@
using Ryujinx.Memory.Range;
using System;
using System.Buffers;
using System.Collections.Generic;
namespace Ryujinx.Memory.Tracking
@@ -300,10 +301,10 @@ namespace Ryujinx.Memory.Tracking
// We use the non-span method here because keeping the lock will cause a deadlock.
regions.Lock.EnterReadLock();
RangeItem<VirtualRegion>[] overlaps = regions.FindOverlapsAsArray(address, size);
RangeItem<VirtualRegion>[] overlaps = regions.FindOverlapsAsArray(address, size, out int length);
regions.Lock.ExitReadLock();
if (overlaps.Length == 0 && !precise)
if (length == 0 && !precise)
{
if (_memoryManager.IsRangeMapped(address, size))
{
@@ -323,8 +324,8 @@ namespace Ryujinx.Memory.Tracking
// Increase the access size to trigger handles with misaligned accesses.
size += (ulong)_pageSize;
}
for (int i = 0; i < overlaps.Length; i++)
for (int i = 0; i < length; i++)
{
VirtualRegion region = overlaps[i].Value;
@@ -337,6 +338,11 @@ namespace Ryujinx.Memory.Tracking
region.Signal(address, size, write, exemptId);
}
}
if (length != 0)
{
ArrayPool<RangeItem<VirtualRegion>>.Shared.Return(overlaps);
}
}
}