massive improvement to quickFlood performance

This commit is contained in:
2025-09-10 14:10:28 -05:00
parent 931334e479
commit cb347f4faa
+25 -4
View File
@@ -14,6 +14,9 @@ var markNeighborIntervals = new Set();
var cancelMarkNeighborRequested = false; var cancelMarkNeighborRequested = false;
var markNeighborRafs = new Set(); var markNeighborRafs = new Set();
var nodeUpdateCache = [];
var edgeUpdateCache = [];
function smoothColorTransition(color1, color2, min, max, current) { function smoothColorTransition(color1, color2, min, max, current) {
// Clamp current between min and max // Clamp current between min and max
const clamped = Math.min(Math.max(current, min), max); const clamped = Math.min(Math.max(current, min), max);
@@ -186,7 +189,8 @@ function quickPacketRaf(startNode, packetInfo, fromNode, opts = {}) {
while (head < queue.length) { while (head < queue.length) {
const { nodeId, ttl, from } = queue[head++]; const { nodeId, ttl, from } = queue[head++];
if (ttl < 0) { if (ttl < 0 && !document.getElementById('showTTL').checked) {
// legacy marking
if (document.getElementById('showTTL').checked) { if (document.getElementById('showTTL').checked) {
markNeighborsAsFailed(nodeId, from, packetId); markNeighborsAsFailed(nodeId, from, packetId);
} }
@@ -197,15 +201,24 @@ function quickPacketRaf(startNode, packetInfo, fromNode, opts = {}) {
if (!node) continue; if (!node) continue;
if (document.getElementById('showTTL').checked) { if (document.getElementById('showTTL').checked) {
edges.update({id: `${from}->${nodeId}`, color: {color: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl+1), highlight: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}}); if (ttl < 0) {
edges.update({id: `${nodeId}->${from}`, color: {color: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl+1), highlight: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}}); edgeUpdateCache.push({id: `${from}->${nodeId}`, color: {color: 'white', highlight: 'white'}});
edgeUpdateCache.push({id: `${nodeId}->${from}`, color: {color: 'white', highlight: 'white'}})
} else {
edgeUpdateCache.push({id: `${from}->${nodeId}`, color: {color: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl+1), highlight: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}})
edgeUpdateCache.push({id: `${nodeId}->${from}`, color: {color: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl+1), highlight: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}})
}
} }
const cache = node.packetCache; const cache = node.packetCache;
if (cache && cache.has(packetId)) continue; if (cache && cache.has(packetId)) continue;
if (document.getElementById('showTTL').checked) { if (document.getElementById('showTTL').checked) {
nodes.update({id: nodeId, color: {background: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}}); if (ttl < 0) {
nodeUpdateCache.push({id: nodeId, color: {background: 'white'}})
} else {
nodeUpdateCache.push({id: nodeId, color: {background: smoothColorTransition('#eb4034', '#40eb34', 0, TTL, ttl)}})
}
} }
cache.add(packetId); cache.add(packetId);
@@ -224,12 +237,20 @@ function quickPacketRaf(startNode, packetInfo, fromNode, opts = {}) {
return; return;
} }
} }
popUpdateCache();
} }
requestAnimationFrame(step); requestAnimationFrame(step);
return { cancel: () => { cancelled = true; } }; return { cancel: () => { cancelled = true; } };
} }
function popUpdateCache() {
nodes.update(nodeUpdateCache);
edges.update(edgeUpdateCache);
nodeUpdateCache = []
edgeUpdateCache = []
}
// This is a modified version of quickPacket that contains some extra logic to save routing tables. // This is a modified version of quickPacket that contains some extra logic to save routing tables.
// It also disables the TTL colors for unreachable nodes to save performance. // It also disables the TTL colors for unreachable nodes to save performance.
function quickRoute(startNode, packetInfo, fromNode) { function quickRoute(startNode, packetInfo, fromNode) {