Memory Changes

* Refactors the RangeList and derivative classes used for handling lists of regions

* The Binary searches are now more performant, relying on edge searches instead of just returning the first matching hit and manually iterating until the edge is found

* Most look-ups now return a RangeItem, which acts as a linked list node now, instead where possible, moving away from Array copies. This should help with some specific lag spikes.

* Made IntrusiveRedBlackTreeNodes act like linked list nodes too to improve the lookup time of minimums, maximums and successors.

* Changed a few cases of HasFlag() into binary operations to save on memory allocations.

In general, [these changes] should increase frame time stability and lag spikes, but at the cost of some overhead to memory look-ups, the result being a very slightly better average fps from my testing (~1-2%).

(cherry picked from commit 01cb33f658)
This commit is contained in:
LotP
2025-09-12 21:23:24 -05:00
committed by KeatonTheBot
parent faa8fb6642
commit ff0daa9f35
17 changed files with 1596 additions and 748 deletions
@@ -89,13 +89,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (baseAddress > currBaseAddr)
{
KMemoryBlock newBlock = currBlock.SplitRightAtAddress(baseAddress);
_blockTree.Add(newBlock);
if (currBlock.Left == null)
_blockTree.Add(newBlock, currBlock);
else
_blockTree.Add(newBlock, currBlock.Predecessor);
}
if (endAddr < currEndAddr)
{
KMemoryBlock newBlock = currBlock.SplitRightAtAddress(endAddr);
_blockTree.Add(newBlock);
if (currBlock.Left == null)
_blockTree.Add(newBlock, currBlock);
else
_blockTree.Add(newBlock, currBlock.Predecessor);
currBlock = newBlock;
}
@@ -143,13 +149,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (baseAddress > currBaseAddr)
{
KMemoryBlock newBlock = currBlock.SplitRightAtAddress(baseAddress);
_blockTree.Add(newBlock);
if (currBlock.Left == null)
_blockTree.Add(newBlock, currBlock);
else
_blockTree.Add(newBlock, currBlock.Predecessor);
}
if (endAddr < currEndAddr)
{
KMemoryBlock newBlock = currBlock.SplitRightAtAddress(endAddr);
_blockTree.Add(newBlock);
if (currBlock.Left == null)
_blockTree.Add(newBlock, currBlock);
else
_blockTree.Add(newBlock, currBlock.Predecessor);
currBlock = newBlock;
}
@@ -199,13 +211,19 @@ namespace Ryujinx.HLE.HOS.Kernel.Memory
if (baseAddress > currBaseAddr)
{
KMemoryBlock newBlock = currBlock.SplitRightAtAddress(baseAddress);
_blockTree.Add(newBlock);
if (currBlock.Left == null)
_blockTree.Add(newBlock, currBlock);
else
_blockTree.Add(newBlock, currBlock.Predecessor);
}
if (endAddr < currEndAddr)
{
KMemoryBlock newBlock = currBlock.SplitRightAtAddress(endAddr);
_blockTree.Add(newBlock);
if (currBlock.Left == null)
_blockTree.Add(newBlock, currBlock);
else
_blockTree.Add(newBlock, currBlock.Predecessor);
currBlock = newBlock;
}