From 9fa2a72a0bba4f7ab1b5efeb20073810fdeece12 Mon Sep 17 00:00:00 2001 From: Damocles Date: Wed, 15 Apr 2026 19:56:24 +0200 Subject: [PATCH] perf: gate cpuCores rebuild behind coreConsumers counter; 30s grace timer + history clear in SystemStats --- modules/Cpu.qml | 12 ++++++++++++ modules/SystemStats.qml | 38 ++++++++++++++++++++++++++------------ 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/modules/Cpu.qml b/modules/Cpu.qml index 00dfeed..a91a0a7 100644 --- a/modules/Cpu.qml +++ b/modules/Cpu.qml @@ -32,6 +32,18 @@ M.BarSection { readonly property bool _anyHover: root._hovered || hoverPanel.panelHovered readonly property bool _showPanel: _anyHover || _pinned + property bool _coreConsumerActive: false + + on_ShowPanelChanged: { + if (_showPanel && !_coreConsumerActive) { + _coreConsumerActive = true; + M.SystemStats.coreConsumers++; + } else if (!_showPanel && _coreConsumerActive) { + _coreConsumerActive = false; + M.SystemStats.coreConsumers--; + } + } + property M.ProcessList _procs: M.ProcessList { sortBy: "cpu" active: root._showPanel diff --git a/modules/SystemStats.qml b/modules/SystemStats.qml index 13c99a8..372a103 100644 --- a/modules/SystemStats.qml +++ b/modules/SystemStats.qml @@ -10,7 +10,19 @@ QtObject { // ── CPU ────────────────────────────────────────────────────────────── property int cpuUsage: 0 property real cpuFreqGhz: 0 - property var cpuCores: [] // [{usage, freq_ghz, history:[]}] + property var cpuCores: [] // [{usage, freq_ghz, history:[]}] — only rebuilt while coreConsumers > 0 + property int coreConsumers: 0 + onCoreConsumersChanged: { + if (coreConsumers > 0) + _coreGraceTimer.stop(); + else + _coreGraceTimer.start(); + } + + property var _coreGraceTimer: Timer { + interval: 30000 + onTriggered: root.cpuCores = [] + } property var cpuCoreMaxFreq: [] property var cpuCoreTypes: [] @@ -44,17 +56,19 @@ QtObject { if (ev.type === "cpu") { root.cpuUsage = ev.usage; root.cpuFreqGhz = ev.freq_ghz; - const histLen = 16; - const prev = root.cpuCores; - root.cpuCores = ev.cores.map((c, i) => { - const oldHist = prev[i]?.history ?? []; - const hist = oldHist.concat([c.usage]); - return { - usage: c.usage, - freq_ghz: c.freq_ghz, - history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist - }; - }); + if (root.coreConsumers > 0) { + const histLen = 16; + const prev = root.cpuCores; + root.cpuCores = ev.cores.map((c, i) => { + const oldHist = prev[i]?.history ?? []; + const hist = oldHist.concat([c.usage]); + return { + usage: c.usage, + freq_ghz: c.freq_ghz, + history: hist.length > histLen ? hist.slice(hist.length - histLen) : hist + }; + }); + } } else if (ev.type === "temp") { root.tempCelsius = ev.celsius; } else if (ev.type === "mem") {