From 82c66e2baba9a5fae7baecee682f52fe2ceba321 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Jun 2017 21:19:14 -0400 Subject: [PATCH] FifoRecorder: Don't allocate ~100.7MB on program startup So, a FifoRecorder instance is instantiated as a file-local variable and used as a singleton (ugh). Most users likely don't regularly use the FIFO player/FIFO recorder, so this is kind of a substantial waste of memory. FifoRecorder's internal RAM and ExRAM vectors are 33554432 and 67108864 bytes respectively, which is around 100.66MB in total. Just on the game list view on a clean build with nothing loaded, this knocks debug build memory usage down from ~232.4MB to ~137.5MB, and release build memory usage down from ~101MB to ~5.7MB. --- Source/Core/Core/FifoPlayer/FifoRecorder.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp index 8f08c6f158..3473b4deb4 100644 --- a/Source/Core/Core/FifoPlayer/FifoRecorder.cpp +++ b/Source/Core/Core/FifoPlayer/FifoRecorder.cpp @@ -18,9 +18,7 @@ static FifoRecorder instance; static std::recursive_mutex sMutex; -FifoRecorder::FifoRecorder() : m_Ram(Memory::RAM_SIZE), m_ExRam(Memory::EXRAM_SIZE) -{ -} +FifoRecorder::FifoRecorder() = default; FifoRecorder::~FifoRecorder() { @@ -36,6 +34,22 @@ void FifoRecorder::StartRecording(s32 numFrames, CallbackFunc finishedCb) FifoAnalyzer::Init(); m_File = new FifoDataFile; + + // TODO: This, ideally, would be deallocated when done recording. + // However, care needs to be taken since global state + // and multithreading don't play well nicely together. + // The video thread may call into functions that utilize these + // despite 'end recording' being requested via StopRecording(). + // (e.g. OpcodeDecoder calling UseMemory()) + // + // Basically: + // - Singletons suck + // - Global variables suck + // - Multithreading with the above two sucks + // + m_Ram.resize(Memory::RAM_SIZE); + m_ExRam.resize(Memory::EXRAM_SIZE); + std::fill(m_Ram.begin(), m_Ram.end(), 0); std::fill(m_ExRam.begin(), m_ExRam.end(), 0);