Browse Source

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 <noreply@anthropic.com>
handoff-20260429-1057
shrimbly 4 months ago
parent
commit
8bf07ad3f9
  1. 5
      src/components/WorkflowCanvas.tsx

5
src/components/WorkflowCanvas.tsx

@ -331,6 +331,11 @@ export function WorkflowCanvas() {
// Apply dimming className to nodes downstream of disabled Switch outputs // Apply dimming className to nodes downstream of disabled Switch outputs
const allNodes = useMemo(() => { 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) => { return nodes.map((node) => {
// Never dim Switch or ConditionalSwitch nodes themselves // Never dim Switch or ConditionalSwitch nodes themselves
if (node.type === "switch" || node.type === "conditionalSwitch") return node; if (node.type === "switch" || node.type === "conditionalSwitch") return node;

Loading…
Cancel
Save