From a22450320b613fea635ec17da62cf069ea86f95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Mon, 4 Dec 2023 13:22:32 +0100 Subject: [PATCH] Some minor changes and comments after memory profiling --- Common/Data/Collections/FixedSizeQueue.h | 9 +++++---- Common/Render/DrawBuffer.h | 10 +++++----- Common/UI/View.cpp | 1 - Core/HLE/sceAudio.cpp | 1 + Core/Util/GameDB.cpp | 15 +++++++++------ UI/BackgroundAudio.h | 3 ++- UI/GameInfoCache.cpp | 2 +- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Common/Data/Collections/FixedSizeQueue.h b/Common/Data/Collections/FixedSizeQueue.h index 621f4f0035..7d0b0998e7 100644 --- a/Common/Data/Collections/FixedSizeQueue.h +++ b/Common/Data/Collections/FixedSizeQueue.h @@ -38,6 +38,10 @@ public: delete [] storage_; } + // Disallow copies. + FixedSizeQueue(FixedSizeQueue &other) = delete; + FixedSizeQueue& operator=(const FixedSizeQueue &other) = delete; + void clear() { head_ = 0; tail_ = 0; @@ -149,6 +153,7 @@ public: ERROR_LOG(COMMON, "Savestate failure: Incompatible queue size."); return; } + // TODO: This is quite wasteful, could just store the actual data. Would be slightly more complex though. DoArray(p, storage_, N); Do(p, head_); Do(p, tail_); @@ -161,10 +166,6 @@ private: int head_; int tail_; int count_; // sacrifice 4 bytes for a simpler implementation. may optimize away in the future. - - // Make copy constructor private for now. - FixedSizeQueue(FixedSizeQueue &other); - FixedSizeQueue& operator=(const FixedSizeQueue &other); }; diff --git a/Common/Render/DrawBuffer.h b/Common/Render/DrawBuffer.h index f16ab1e62c..c8ac2815f4 100644 --- a/Common/Render/DrawBuffer.h +++ b/Common/Render/DrawBuffer.h @@ -13,11 +13,6 @@ struct Atlas; -enum { - // Enough? - MAX_VERTS = 65536, -}; - enum { ALIGN_LEFT = 0, ALIGN_RIGHT = 16, @@ -186,6 +181,11 @@ public: saturation_ = saturation; } + enum { + // TODO: Can probably shrink this. Currently consumes 1.5MB. + MAX_VERTS = 65536, + }; + private: struct Vertex { float x, y, z; diff --git a/Common/UI/View.cpp b/Common/UI/View.cpp index 6ebac93d38..b60f6ac88d 100644 --- a/Common/UI/View.cpp +++ b/Common/UI/View.cpp @@ -99,7 +99,6 @@ View::~View() { // Could use unique_ptr, but then we have to include tween everywhere. for (auto &tween : tweens_) delete tween; - tweens_.clear(); } void View::Update() { diff --git a/Core/HLE/sceAudio.cpp b/Core/HLE/sceAudio.cpp index b518c8fc61..4b805ea6aa 100644 --- a/Core/HLE/sceAudio.cpp +++ b/Core/HLE/sceAudio.cpp @@ -35,6 +35,7 @@ const int AUDIO_ROUTING_SPEAKER_ON = 1; int defaultRoutingMode = AUDIO_ROUTING_SPEAKER_ON; int defaultRoutingVolMode = AUDIO_ROUTING_SPEAKER_ON; +// TODO: These are way oversized and together consume 4MB of memory. extern FixedSizeQueue chanSampleQueues[PSP_AUDIO_CHANNEL_MAX + 1]; // The extra channel is for SRC/Output2/Vaudio. diff --git a/Core/Util/GameDB.cpp b/Core/Util/GameDB.cpp index 97fc02b0c7..8c4163dc6c 100644 --- a/Core/Util/GameDB.cpp +++ b/Core/Util/GameDB.cpp @@ -34,8 +34,7 @@ static void SplitCSVLine(const std::string_view str, std::vector splitSV(std::string_view strv, char delim, bool removeWhiteSpace) { - std::vector output; +static void splitSV(std::string_view strv, char delim, bool removeWhiteSpace, std::vector *output) { size_t first = 0; while (first < strv.size()) { const auto second = strv.find(delim, first); @@ -47,13 +46,12 @@ static std::vector splitSV(std::string_view strv, char delim, if (removeWhiteSpace) { line = StripSpaces(line); } - output.emplace_back(line); + output->emplace_back(line); } if (second == std::string_view::npos) break; first = second + 1; } - return output; } bool GameDB::LoadFromVFS(VFSInterface &vfs, const char *filename) { @@ -64,9 +62,12 @@ bool GameDB::LoadFromVFS(VFSInterface &vfs, const char *filename) { contents_ = std::string((const char *)data, size); delete[] data; - // Split the string into views of each line, keeping the original. - std::vector lines = splitSV(contents_, '\n', false); + const size_t RESERVE_COUNT = 2820; // ~ known current line count + // Split the string into views of each line, keeping the original. + std::vector lines; + lines.reserve(RESERVE_COUNT); + splitSV(contents_, '\n', false, &lines); SplitCSVLine(lines[0], columns_); const size_t titleColumn = GetColumnIndex("Title"); @@ -76,6 +77,8 @@ bool GameDB::LoadFromVFS(VFSInterface &vfs, const char *filename) { const size_t sizeColumn = GetColumnIndex("Size"); std::vector items; + items.reserve(8); + lines_.reserve(RESERVE_COUNT); for (size_t i = 1; i < lines.size(); i++) { auto &lineString = lines[i]; SplitCSVLine(lineString, items); diff --git a/UI/BackgroundAudio.h b/UI/BackgroundAudio.h index 178ea2e1d6..3c869485dc 100644 --- a/UI/BackgroundAudio.h +++ b/UI/BackgroundAudio.h @@ -67,7 +67,8 @@ private: void Clear(bool hard); enum { - BUFSIZE = 44100, + // 0.5 ms buffer at 44.1 khz should be enough. + BUFSIZE = 22050, }; std::mutex mutex_; diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 2733dd8a20..fcca47a348 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -764,7 +764,7 @@ void GameInfoCache::WaitUntilDone(std::shared_ptr &info) { std::shared_ptr GameInfoCache::GetInfo(Draw::DrawContext *draw, const Path &gamePath, int wantFlags) { std::shared_ptr info; - std::string pathStr = gamePath.ToString(); + const std::string &pathStr = gamePath.ToString(); auto iter = info_.find(pathStr); if (iter != info_.end()) {