From 5bf9018ad357d642eecbcde0e11d5f9d00658b75 Mon Sep 17 00:00:00 2001 From: Gabriel Saillard Date: Thu, 6 May 2021 12:29:58 +0200 Subject: [PATCH] perf(win32): throttle expensive systeminformation calls --- src/classes/cpuinfo.class.js | 12 ++++++++++++ src/classes/ramwatcher.class.js | 5 +++++ src/classes/toplist.class.js | 10 ++++++++++ 3 files changed, 27 insertions(+) diff --git a/src/classes/cpuinfo.class.js b/src/classes/cpuinfo.class.js index 1ba9970..b3425cf 100644 --- a/src/classes/cpuinfo.class.js +++ b/src/classes/cpuinfo.class.js @@ -97,9 +97,12 @@ class Cpuinfo { } // Init updater + this.updatingCPUload = false; this.updateCPUload(); if (process.platform !== "win32") {this.updateCPUtemp();} + this.updatingCPUspeed = false; this.updateCPUspeed(); + this.updatingCPUtasks = false; this.updateCPUtasks(); this.loadUpdater = setInterval(() => { this.updateCPUload(); @@ -118,6 +121,8 @@ class Cpuinfo { }); } updateCPUload() { + if (this.updatingCPUload) return; + this.updatingCPUload = true; window.si.currentLoad().then(data => { let average = [[], []]; @@ -141,6 +146,7 @@ class Cpuinfo { // Fail silently, DOM element is probably getting refreshed (new theme, etc) } }); + this.updatingCPUload = false; }); } updateCPUtemp() { @@ -153,6 +159,8 @@ class Cpuinfo { }); } updateCPUspeed() { + if (this.updatingCPUspeed) return; + this.updatingCPUspeed = true window.si.cpu().then(data => { try { document.getElementById("mod_cpuinfo_speed_min").innerText = `${data.speed}GHz`; @@ -160,15 +168,19 @@ class Cpuinfo { } catch(e) { // See above notice } + this.updatingCPUspeed = false; }); } updateCPUtasks() { + if (this.updatingCPUtasks) return; + this.updatingCPUtasks = true; window.si.processes().then(data => { try { document.getElementById("mod_cpuinfo_tasks").innerText = `${data.all}`; } catch(e) { // See above notice } + this.updatingCPUtasks = false; }); } } diff --git a/src/classes/ramwatcher.class.js b/src/classes/ramwatcher.class.js index a55f2ff..12eb498 100644 --- a/src/classes/ramwatcher.class.js +++ b/src/classes/ramwatcher.class.js @@ -29,12 +29,15 @@ class RAMwatcher { this.shuffleArray(this.points); // Init updaters + this.currentlyUpdating = false; this.updateInfo(); this.infoUpdater = setInterval(() => { this.updateInfo(); }, 1500); } updateInfo() { + if (this.currentlyUpdating) return; + this.currentlyUpdating = true; window.si.mem().then(data => { if (data.free+data.used !== data.total) throw("RAM Watcher Error: Bad memory values"); @@ -70,6 +73,8 @@ class RAMwatcher { let usedSwapGiB = Math.round((data.swapused/1073742000)*10)/10; document.getElementById("mod_ramwatcher_swaptext").innerText = `${usedSwapGiB} GiB`; + + this.currentlyUpdating = false; }); } shuffleArray(array) { diff --git a/src/classes/toplist.class.js b/src/classes/toplist.class.js index cc381fe..a4ffcc6 100644 --- a/src/classes/toplist.class.js +++ b/src/classes/toplist.class.js @@ -12,12 +12,17 @@ class Toplist { this.parent.append(this._element); + this.currentlyUpdating = false; + this.updateList(); this.listUpdater = setInterval(() => { this.updateList(); }, 2000); } updateList() { + if (this.currentlyUpdating) return; + + this.currentlyUpdating = true; window.si.processes().then(data => { if (window.settings.excludeThreadsFromToplist === true) { data.list = data.list.sort((a, b) => { @@ -48,6 +53,7 @@ class Toplist { ${Math.round(proc.mem*10)/10}%`; document.getElementById("mod_toplist_table").append(el); }); + this.currentlyUpdating = false; }); } @@ -55,6 +61,7 @@ class Toplist { let sortKey; let ascending = false; let removed = false; + let currentlyUpdating = false; function setSortKey(fieldName){ if (sortKey === fieldName){ @@ -91,6 +98,8 @@ class Toplist { } function updateProcessList() { + if (currentlyUpdating) return; + currentlyUpdating = true; window.si.processes().then(data => { if (window.settings.excludeThreadsFromToplist === true) { data.list = data.list.sort((a, b) => { @@ -110,6 +119,7 @@ class Toplist { proc.runtime = new Date(Date.now() - Date.parse(proc.started)); }); + currentlyUpdating = false; let list = data.list.sort((a, b) => { switch (sortKey) { case "PID":