Memmap: Optimize UpdateLogicalMemory by merging mappings

Instead of creating many 128 KiB mappings, we can create a few large
mappings. On my Windows PC, this speeds up GameCube (FakeVMEM) game boot
times by about 200 ms and Wii game boot times by about 60 ms. Loading
savestates is also faster, by about 45 ms for GameCube (FakeVMEM) games
and 5 ms for Wii games. The impact is presumably smaller on other OSes
because Windows is particularly slow at creating mappings.
This commit is contained in:
JosJuice
2025-06-21 20:00:39 +02:00
parent 2047eaf1d8
commit ac84ea17a6

View File

@ -248,9 +248,24 @@ void MemoryManager::UpdateLogicalMemory(const PowerPC::BatTable& dbat_table)
if (dbat_table[i] & PowerPC::BAT_PHYSICAL_BIT)
{
u32 logical_address = i << PowerPC::BAT_INDEX_SHIFT;
// TODO: Merge adjacent mappings to make this faster.
u32 logical_size = PowerPC::BAT_PAGE_SIZE;
u32 translated_address = dbat_table[i] & PowerPC::BAT_RESULT_MASK;
while (i + 1 < dbat_table.size())
{
if (!(dbat_table[i + 1] & PowerPC::BAT_PHYSICAL_BIT))
{
++i;
break;
}
if ((dbat_table[i + 1] & PowerPC::BAT_RESULT_MASK) != translated_address + logical_size)
break;
++i;
logical_size += PowerPC::BAT_PAGE_SIZE;
}
for (const auto& physical_region : m_physical_regions)
{
if (!physical_region.active)