From 8bf07ad3f90b0cb0e19af6ad67451414394baa59 Mon Sep 17 00:00:00 2001 From: shrimbly Date: Tue, 10 Mar 2026 22:04:25 +1300 Subject: [PATCH] perf: short-circuit allNodes useMemo when no dimming is active When dimmedNodeIds is empty and no node has a stale switch-dimmed class, return the nodes array directly (same reference, zero iteration). The .map() + regex only runs when dimming is actually active, which is the uncommon case for most workflows. Co-Authored-By: Claude Opus 4.6 --- src/components/WorkflowCanvas.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/components/WorkflowCanvas.tsx b/src/components/WorkflowCanvas.tsx index 1a5103b8..665ae600 100644 --- a/src/components/WorkflowCanvas.tsx +++ b/src/components/WorkflowCanvas.tsx @@ -331,6 +331,11 @@ export function WorkflowCanvas() { // Apply dimming className to nodes downstream of disabled Switch outputs const allNodes = useMemo(() => { + // Fast path: no dimming active and no stale dimmed classes to clean up + if (dimmedNodeIds.size === 0 && !nodes.some((n) => n.className?.includes("switch-dimmed"))) { + return nodes; + } + return nodes.map((node) => { // Never dim Switch or ConditionalSwitch nodes themselves if (node.type === "switch" || node.type === "conditionalSwitch") return node;