mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-21 02:01:14 +02:00
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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user