From 78cf0738766406a61b3c6af2faf234dbfe9759c3 Mon Sep 17 00:00:00 2001 From: wisplite Date: Mon, 8 Sep 2025 18:10:00 -0500 Subject: [PATCH] add extra performance optimizations for large networks, and an explanation on the notice --- index.html | 1 + script.js | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/index.html b/index.html index 5c4212c..87782df 100644 --- a/index.html +++ b/index.html @@ -83,6 +83,7 @@

+
diff --git a/script.js b/script.js index 585caec..6675de2 100644 --- a/script.js +++ b/script.js @@ -150,6 +150,29 @@ const markNeighborsAsFailed = (nodeId, from, packetId, visited = new Set()) => { } visited.add(nodeId); + if (warningModalShown) { + // enable walkthrough mode to prevent browser from freezing + const neighborsSnapshot = (nodeTable[nodeId]?.outgoing?.slice()) || []; + const neighborsLength = neighborsSnapshot.length; + let currentIdx = 0; + const intervalId = setInterval(() => { + if (currentIdx < neighborsLength) { + const neighbor = neighborsSnapshot[currentIdx]; + if (!visited.has(neighbor) && + !nodeTable[neighbor]?.packetCache?.includes(packetId) && + neighbor !== from) { + nodes.update({id: neighbor, color: {background: 'white'}}); + edges.update({id: `${nodeId}->${neighbor}`, color: {color: 'white', highlight: '#97c2fc'}}); + markNeighborsAsFailed(neighbor, nodeId, packetId, visited); + } + currentIdx++; + } else { + clearInterval(intervalId); + } + }, 10); + return; + } + const neighborsSnapshot = (nodeTable[nodeId]?.outgoing?.slice()) || []; for (let neighbor of neighborsSnapshot) { if (visited.has(neighbor)) { @@ -411,6 +434,8 @@ function onNodeAdd() { warningModalShown = true; document.getElementById('warningModal').style.display = 'block'; document.getElementById('warningModalMessage').innerHTML = 'Large network detected; simulation speed will be reduced.'; + document.getElementById('warningModalCustomContent').innerHTML = `
What does this mean? +

The simulation, by default, computes every node's connections 100 'times' per second. Due to the size of this network, this could cause the browser to freeze. To prevent this, the update interval (found in engine settings) is now locked to a multiple of the number of nodes. Additionally, when computing which nodes weren't reached after a packet is sent, the simulation will now walk through the network in steps rather than computing everything at once.

`; document.getElementById('updateInterval').disabled = true; document.getElementById('updateInterval').value = nodeLength*2; UPDATE_INTERVAL = nodeLength*2;