From 88fa13dd1ac909e5390749fe61cb01ece4ef8389 Mon Sep 17 00:00:00 2001 From: DanS Date: Sat, 10 Oct 2026 09:50:03 -0500 Subject: [PATCH] perf(mining): sample system RAM at most once a second The Mining tab's memory bar read used system RAM and the wallet's own memory on the UI thread every frame: synchronous OS queries, on Linux an open and parse of /proc/meminfo and /proc/self/status per frame. Both are now sampled at most once a second; the first frame after more than a second idle resamples at once. Total RAM was already cached and daemon RAM already comes from a background sampler. The used-RAM and wallet-memory readings in the bar and its tooltip now refresh at most once a second; what they show is unchanged. Co-Authored-By: Claude Opus 5.5 --- src/ui/windows/mining_earnings.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/ui/windows/mining_earnings.cpp b/src/ui/windows/mining_earnings.cpp index 94f1d4e..186f23c 100644 --- a/src/ui/windows/mining_earnings.cpp +++ b/src/ui/windows/mining_earnings.cpp @@ -307,9 +307,20 @@ void RenderMiningEarnings(App* app, const WalletState& state, const MiningInfo& // ---- Memory bar — centered in remaining space below details ---- { - double totalRAM = dragonx::util::Platform::getTotalSystemRAM_MB(); - double usedRAM = dragonx::util::Platform::getUsedSystemRAM_MB(); - double selfRAM = dragonx::util::Platform::getSelfMemoryUsageMB(); + double totalRAM = dragonx::util::Platform::getTotalSystemRAM_MB(); // cached inside Platform + // Used/self RAM are synchronous OS reads (/proc/meminfo + /proc/self/status on Linux): sample them at + // most once a second, not every frame. The first frame after >1 s idle resamples immediately. + static double s_usedRAM = 0.0, s_selfRAM = 0.0; + static int64_t s_ramSampledMs = 0; + static bool s_ramSampled = false; + if (!s_ramSampled || IntervalElapsed(nowMs, s_ramSampledMs, 1000)) { + s_usedRAM = dragonx::util::Platform::getUsedSystemRAM_MB(); + s_selfRAM = dragonx::util::Platform::getSelfMemoryUsageMB(); + s_ramSampledMs = nowMs; + s_ramSampled = true; + } + double usedRAM = s_usedRAM; + double selfRAM = s_selfRAM; double daemonRAM = app->getDaemonMemoryUsageMB(); // Include xmrig memory when pool mining double xmrigRAM = state.pool_mining.memory_used / (1024.0 * 1024.0); // bytes -> MB