Removed throttling for node and counter updates to improve performance and reach 60fps.

This commit is contained in:
Benjamin Arntzen (aider)
2024-07-03 23:59:28 -03:00
parent 384ffb7667
commit 12dbf40215
+5 -15
View File
@@ -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);
}