⚡ Bolt: Replace O(N) array find with O(1) map lookups for node selection#68
⚡ Bolt: Replace O(N) array find with O(1) map lookups for node selection#68mbayue wants to merge 2 commits into
Conversation
💡 What: Replaced linear array `.find()` lookups with O(1) `Map.get()` lookups across `AISidebar.tsx`, `useAiCenterState.ts`, and `VizPage.tsx`. Pre-computes a map of `node.id -> node` using `useMemo`. 🎯 Why: Prevents blocking the React render cycle when looking up `selectedNode` in large graphs with thousands of nodes, which was previously happening via linear scans every render. 📊 Impact: Expected to reduce lookup times for selected node resolution from O(N) to O(1), directly mitigating frame drops during graph interactions for large codebases. 🔬 Measurement: Can be verified by profiling React render times during interactions in a repository with > 1,000 files. Co-authored-by: mbayue <[email protected]>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 5/5
src/components/viz/ai-sidebar/hooks/useAiCenterState.tsincludes an AI-branded, copy-pasted comment that adds noise rather than clarity; merging as-is is unlikely to break behavior but can reduce maintainability and reviewer trust in future diffs. This PR is safe to merge, but it would be cleaner to remove or rewrite the comment to capture file-specific intent before merging.
Architecture diagram
sequenceDiagram
participant Store as VizStore/State
participant Comp as React Component
participant Graph as Graph Nodes Array
participant Map as nodeById Map (useMemo)
participant SelectedId as selectedNodeId
Note over Store,SelectedId: O(1) Lookup Path (Post-PR)
Comp->>Store: useVizStore() → selectedNodeId, analysis.graph.nodes
Comp->>Graph: access nodes array
Comp->>Map: useMemo → new Map(nodes.map(n=>[n.id, n]))
Map-->>Comp: nodeById (Map instance)
alt selectedNodeId is not null
Comp->>Map: nodeById.get(selectedNodeId)
Map-->>Comp: selectedNode (GraphNode) or null
else selectedNodeId is null
Comp->>Comp: selectedNode = null (no lookup needed)
end
Comp->>Comp: Render with selectedNode
Note over Comp: O(1) Map.get() avoids O(N) array scan each render
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
💡 What: Replaced linear array `.find()` lookups with O(1) `Map.get()` lookups across `AISidebar.tsx`, `useAiCenterState.ts`, and `VizPage.tsx`. Pre-computes a map of `node.id -> node` using `useMemo`. 🎯 Why: Prevents blocking the React render cycle when looking up `selectedNode` in large graphs with thousands of nodes, which was previously happening via linear scans every render. 📊 Impact: Expected to reduce lookup times for selected node resolution from O(N) to O(1), directly mitigating frame drops during graph interactions for large codebases. 🔬 Measurement: Can be verified by profiling React render times during interactions in a repository with > 1,000 files. Co-authored-by: mbayue <[email protected]>
⚡ Bolt: Replace O(N) array find with O(1) map lookups for node selection
💡 What: Replaced linear array
.find()lookups with O(1)Map.get()lookups acrossAISidebar.tsx,useAiCenterState.ts, andVizPage.tsx. Pre-computes a map ofnode.id -> nodeusinguseMemo.🎯 Why: Prevents blocking the React render cycle when looking up
selectedNodein large graphs with thousands of nodes, which was previously happening via linear scans every render.📊 Impact: Expected to reduce lookup times for selected node resolution from O(N) to O(1), directly mitigating frame drops during graph interactions for large codebases.
🔬 Measurement: Can be verified by profiling React render times during interactions in a repository with > 1,000 files.
PR created automatically by Jules for task 7442781794420946948 started by @mbayue
Summary by cubic
Replaced O(N) array
.find()with O(1)Map.get()for resolvingselectedNode, removing render-time scans and smoothing interactions on large graphs.nodeByIdviauseMemoand use it inAISidebar.tsx,useAiCenterState.ts, andVizPage.tsx.useMemodeps inVizPage.tsxto avoid stale reads; behavior unchanged, lookups faster.Written for commit 91cd23e. Summary will update on new commits.