From 12dbf402153ad69c9fab2977fb1db6d8efafd2e1 Mon Sep 17 00:00:00 2001 From: "Benjamin Arntzen (aider)" Date: Wed, 3 Jul 2024 23:59:28 -0300 Subject: [PATCH] Removed throttling for node and counter updates to improve performance and reach 60fps. --- public/app.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/public/app.js b/public/app.js index 3f944be..020647d 100644 --- a/public/app.js +++ b/public/app.js @@ -341,33 +341,23 @@ window.addEventListener('resize', resizeAndCenterNetwork); // Removed the stabilizationIterationsDone event listener to avoid redundant calls to resizeAndCenterNetwork -let lastUpdateTime = 0; let lastPieChartUpdateTime = 0; -let lastCounterUpdateTime = 0; -const updateInterval = 120; // 120ms throttle -const counterUpdateInterval = 50; // 50ms throttle for counter +const pieChartUpdateInterval = 1000; // Update pie chart every second function updateNodes() { - const currentTime = performance.now(); - if (currentTime - lastUpdateTime >= updateInterval && nodesToUpdate.length > 0) { + if (nodesToUpdate.length > 0) { nodes.update(nodesToUpdate); nodesToUpdate = []; calculateSmallGroups(); - lastUpdateTime = currentTime; + updateCounter(); } - // Separate throttle for pie chart update - if (currentTime - lastPieChartUpdateTime >= updateInterval) { + const currentTime = performance.now(); + if (currentTime - lastPieChartUpdateTime >= pieChartUpdateInterval) { updatePieChart(); lastPieChartUpdateTime = currentTime; } - // Separate throttle for counter update - if (currentTime - lastCounterUpdateTime >= counterUpdateInterval) { - updateCounter(); - lastCounterUpdateTime = currentTime; - } - requestAnimationFrame(updateNodes); }