From bbae989e7963a2699c727638c2a1f61202963302 Mon Sep 17 00:00:00 2001 From: Hugo Gu Date: Mon, 25 May 2026 21:23:04 +0800 Subject: [PATCH] fix(web): cap tree layout spring iterations and remove unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Finding A (blocker): calculateTreeLayout runs 14 synchronous spring iterations over all edges and nodes — O(N×E×14) + O(N log N) per layer per iteration — with no size guard. At 10K+ nodes this freezes the main thread for several seconds. Fix: make SPRING_ITERATIONS adaptive: - N > 10 000 → 0 iterations (proportional initial layout only) - N > 3 000 → 4 iterations - otherwise → 14 iterations (unchanged behaviour for small graphs) Also removes the unused `const r` at useSigma.ts:1314, which was a leftover after the radial-resistance decomposition was removed. This clears the CodeQL "unused variable" warning (Finding G). Co-authored-by: Claude AI-model: claude-sonnet-4-6 --- gitnexus-web/src/hooks/useSigma.ts | 1 - gitnexus-web/src/lib/tree-layout.ts | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/gitnexus-web/src/hooks/useSigma.ts b/gitnexus-web/src/hooks/useSigma.ts index e24d3a376..0bf48c5f4 100644 --- a/gitnexus-web/src/hooks/useSigma.ts +++ b/gitnexus-web/src/hooks/useSigma.ts @@ -1311,7 +1311,6 @@ export const useSigma = (options: UseSigmaOptions = {}): UseSigmaReturn => { const targetR = ringTargetR[Math.min(ring, CIRCLES_RING_COUNT - 1)]; const x = attrs.x; const y = attrs.y; - const r = Math.sqrt(x * x + y * y) || 1; // Soft-wall gravity (force 1) already handles radial boundary // enforcement — no separate resistance decomposition needed. diff --git a/gitnexus-web/src/lib/tree-layout.ts b/gitnexus-web/src/lib/tree-layout.ts index c713c0bb0..5fb284d5c 100644 --- a/gitnexus-web/src/lib/tree-layout.ts +++ b/gitnexus-web/src/lib/tree-layout.ts @@ -501,7 +501,11 @@ export function calculateTreeLayout(graph: KnowledgeGraph): Map 10000 ? 0 : nodeCount > 3000 ? 4 : 14; for (let iter = 0; iter < SPRING_ITERATIONS; iter++) { const deltaXByNode = new Map();