From b6b04fa6c56e0804c3b4b31efbaf1a7bb640ec67 Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Sun, 31 Jul 2022 13:11:57 +0100 Subject: [PATCH] Use small_vector for VMM TranslateRange results This was the source of a lot of heap allocs, moving to small_vector helps to avoid most of them --- app/src/main/cpp/skyline/common/address_space.h | 5 ++++- app/src/main/cpp/skyline/common/address_space.inc | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/src/main/cpp/skyline/common/address_space.h b/app/src/main/cpp/skyline/common/address_space.h index e3f1965c..39cf2b39 100644 --- a/app/src/main/cpp/skyline/common/address_space.h +++ b/app/src/main/cpp/skyline/common/address_space.h @@ -3,6 +3,7 @@ #pragma once +#include #include #include @@ -10,6 +11,8 @@ namespace skyline { template concept AddressSpaceValid = std::is_unsigned_v && sizeof(VaType) * 8 >= AddressSpaceBits; + using TranslatedAddressRange = boost::container::small_vector, 1>; + struct EmptyStruct {}; /** @@ -116,7 +119,7 @@ namespace skyline { /** * @return A vector of all physical ranges inside of the given virtual range */ - std::vector> TranslateRange(VaType virt, VaType size, std::function)> cpuAccessCallback = {}); + TranslatedAddressRange TranslateRange(VaType virt, VaType size, std::function)> cpuAccessCallback = {}); void Read(u8 *destination, VaType virt, VaType size, std::function)> cpuAccessCallback = {}); diff --git a/app/src/main/cpp/skyline/common/address_space.inc b/app/src/main/cpp/skyline/common/address_space.inc index bec53a73..00607a04 100644 --- a/app/src/main/cpp/skyline/common/address_space.inc +++ b/app/src/main/cpp/skyline/common/address_space.inc @@ -233,7 +233,7 @@ namespace skyline { munmap(sparseMap, SparseMapSize); } - MM_MEMBER(std::vector>)::TranslateRange(VaType virt, VaType size, std::function)> cpuAccessCallback) { + MM_MEMBER(TranslatedAddressRange)::TranslateRange(VaType virt, VaType size, std::function)> cpuAccessCallback) { TRACE_EVENT("containers", "FlatMemoryManager::TranslateRange"); std::scoped_lock lock(this->blockMutex); @@ -247,7 +247,7 @@ namespace skyline { u8 *blockPhys{predecessor->phys + (virt - predecessor->virt)}; VaType blockSize{std::min(successor->virt - virt, size)}; - std::vector> ranges; + TranslatedAddressRange ranges; while (size) { // Return a zeroed out map to emulate sparse mappings