Skip to content

⚡ Bolt: [네트워크 그래프 관계 및 노드 선택 O(1) 맵 최적화] - #1325

Closed
seonghobae wants to merge 1 commit into
developfrom
perf-optimize-network-graph-lookups-9175516969188916035
Closed

⚡ Bolt: [네트워크 그래프 관계 및 노드 선택 O(1) 맵 최적화]#1325
seonghobae wants to merge 1 commit into
developfrom
perf-optimize-network-graph-lookups-9175516969188916035

Conversation

@seonghobae

@seonghobae seonghobae commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

💡 What

  • NetworkGraph.tsx에서 노드/관계 선택 및 레이블 렌더링 시 발생하는 edges.find()nodes.find()(O(N))를 useMemo로 사전 계산된 Map.get()(O(1))으로 대체했습니다.

🎯 Why

  • 복잡한 네트워크 그래프를 렌더링하고 유저 인터랙션 시, 노드나 관계의 개수가 많아질 경우 매번 배열 전체를 순회(O(N))하게 되어 불필요한 연산 오버헤드와 프레임 저하가 발생할 수 있습니다. 맵을 사용하면 이 병목을 해결할 수 있습니다.

📊 Impact

  • 그래프 노드 및 엣지 선택 이벤트 발생 시 탐색 복잡도를 O(N)에서 O(1)로 줄여 빠른 UI 응답성을 제공합니다.

🔬 Measurement

  • pnpm testpnpm run test:e2e 통과 여부 확인을 통해 정상 작동을 검증했습니다.

PR created automatically by Jules for task 9175516969188916035 started by @seonghobae

Summary by CodeRabbit

  • Performance
    • Improved responsiveness when selecting nodes and relationships in the network graph.
    • Faster updates when changing graph selections or using related dropdown controls.
    • Existing loading, error, empty-state, and selection behavior remains unchanged.

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a NetworkGraph implementation and optimizes its node and edge selection paths with memoized Map lookups. Planning files document the implementation and verification steps.

Changes

NetworkGraph changes

Layer / File(s) Summary
NetworkGraph component implementation
frontend/src/components/NetworkGraph.tsx.orig
Adds network data normalization, sanitized graph rendering, selection handling, controls, cleanup, and loading, error, and empty states.
Memoized graph object lookups
frontend/src/components/NetworkGraph.tsx
Adds memoized node and edge maps. Selection handlers, dropdown handlers, and graph effects use the maps instead of repeated array searches.
Lookup optimization planning and guidance
plan.md, get_plan.py, .jules/bolt.md
Documents the lookup changes, hook dependencies, verification steps, and submission metadata.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: optimizing network graph relationship and node selection with O(1) map lookups.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf-optimize-network-graph-lookups-9175516969188916035

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@frontend/src/components/NetworkGraph.tsx`:
- Around line 174-190: Update the nodeObjectMap construction in NetworkGraph to
preserve the first node for each normalized string ID by inserting only when the
map does not already contain the key. Apply the same first-entry behavior as
edgeObjectMap or nodeMap so duplicate and string-equivalent IDs cannot overwrite
earlier selections.

In `@plan.md`:
- Around line 119-139: Update the validation and pre-commit sections of plan.md
to record each required command exactly—lint, typecheck, build, test, and
test:e2e from the frontend directory—along with its actual result. Add relevant
academic citations with links and brief summaries supporting the performance
optimization, and commit paper PDFs only when redistribution is permitted;
ensure the PR description reflects the completed evidence and citations.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2354dea6-522c-4509-88bc-e9fedcbf1979

📥 Commits

Reviewing files that changed from the base of the PR and between f0207b4 and 35c67ae.

📒 Files selected for processing (5)
  • .jules/bolt.md
  • frontend/src/components/NetworkGraph.tsx
  • frontend/src/components/NetworkGraph.tsx.orig
  • get_plan.py
  • plan.md

Comment on lines +174 to +190
const edgeObjectMap = useMemo(() => {
const map = new Map<string, Edge>();
for (const edge of edges) {
if (edge.id != null) {
map.set(String(edge.id), edge);
}
}
return map;
}, [edges]);

const nodeObjectMap = useMemo(() => {
const map = new Map<string, Node>();
for (const node of nodes) {
map.set(String(node.id), node);
}
return map;
}, [nodes]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Preserve first-match selection for colliding IDs.

The previous edges.find() and nodes.find() calls returned the first string-equivalent ID. These maps overwrite earlier entries. A 1 and "1", or duplicate backend IDs, now select the last object. nodeMap keeps the first label while nodeObjectMap selects the last node, so the label and selected node can disagree.

Keep the first map entry, or reject duplicate normalized IDs during normalization.

Proposed fix
   for (const edge of edges) {
     if (edge.id != null) {
-      map.set(String(edge.id), edge);
+      const key = String(edge.id);
+      if (!map.has(key)) {
+        map.set(key, edge);
+      }
     }
   }

Apply the same map.has(key) guard to nodeObjectMap.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const edgeObjectMap = useMemo(() => {
const map = new Map<string, Edge>();
for (const edge of edges) {
if (edge.id != null) {
map.set(String(edge.id), edge);
}
}
return map;
}, [edges]);
const nodeObjectMap = useMemo(() => {
const map = new Map<string, Node>();
for (const node of nodes) {
map.set(String(node.id), node);
}
return map;
}, [nodes]);
const edgeObjectMap = useMemo(() => {
const map = new Map<string, Edge>();
for (const edge of edges) {
if (edge.id != null) {
const key = String(edge.id);
if (!map.has(key)) {
map.set(key, edge);
}
}
}
return map;
}, [edges]);
const nodeObjectMap = useMemo(() => {
const map = new Map<string, Node>();
for (const node of nodes) {
const key = String(node.id);
if (!map.has(key)) {
map.set(key, node);
}
}
return map;
}, [nodes]);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@frontend/src/components/NetworkGraph.tsx` around lines 174 - 190, Update the
nodeObjectMap construction in NetworkGraph to preserve the first node for each
normalized string ID by inserting only when the map does not already contain the
key. Apply the same first-entry behavior as edgeObjectMap or nodeMap so
duplicate and string-equivalent IDs cannot overwrite earlier selections.

Comment thread plan.md
Comment on lines +119 to +139
2. Format the code by running `run_in_bash_session` with `cd frontend && pnpm run lint --fix`.
3. Use the `read_file` tool on `frontend/src/components/NetworkGraph.tsx` to confirm changes.
4. Test by running `run_in_bash_session` with `cd frontend && pnpm run test && pnpm run build && pnpm run test:e2e`.
5. Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done.
6. Submit PR using the `submit` tool with exactly:
- branch_name: "perf-optimize-network-graph-lookups"
- commit_message: "⚡ Bolt: 네트워크 그래프 O(N) 탐색을 O(1) 맵 탐색으로 최적화"
- title: "⚡ Bolt: [네트워크 그래프 관계 및 노드 선택 O(1) 맵 최적화]"
- description: """
💡 What
- `NetworkGraph.tsx`에서 노드/관계 선택 및 레이블 렌더링 시 발생하는 `edges.find()`와 `nodes.find()`(`O(N)`)를 `useMemo`로 사전 계산된 `Map.get()`(`O(1)`)으로 대체했습니다.

🎯 Why
- 복잡한 네트워크 그래프를 렌더링하고 유저 인터랙션 시, 노드나 관계의 개수가 많아질 경우 매번 배열 전체를 순회(`O(N)`)하게 되어 불필요한 연산 오버헤드와 프레임 저하가 발생할 수 있습니다. 맵을 사용하면 이 병목을 해결할 수 있습니다.

📊 Impact
- 그래프 노드 및 엣지 선택 이벤트 발생 시 탐색 복잡도를 O(N)에서 O(1)로 줄여 빠른 UI 응답성을 제공합니다.

🔬 Measurement
- `pnpm test` 및 `pnpm run test:e2e` 통과 여부 확인을 통해 정상 작동을 검증했습니다.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

jq '.scripts' frontend/package.json

Repository: ContextualWisdomLab/naruon

Length of output: 773


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- AGENTS.md ---'
cat AGENTS.md

printf '%s\n' '--- plan.md lines 119-139 ---'
nl -ba plan.md | sed -n '119,139p'

printf '%s\n' '--- frontend/package.json scripts ---'
jq '.scripts' frontend/package.json

printf '%s\n' '--- relevant verification configuration/files ---'
git ls-files | grep -E '(^|/)(AGENTS\.md|package\.json|pnpm-lock\.yaml|vitest\.config|playwright\.config|tsconfig\.json|eslint\.config|\.eslintrc)' | head -80

Repository: ContextualWisdomLab/naruon

Length of output: 49158


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- plan.md lines 119-139 ---'
python3 - <<'PY'
from pathlib import Path
path = Path("plan.md")
lines = path.read_text().splitlines()
for number in range(119, min(139, len(lines)) + 1):
    print(f"{number:4}: {lines[number - 1]}")
PY

printf '%s\n' '--- repository references and plan verification wording ---'
rg -n -i --glob '!.git/**' \
  'academic|literature|citation|verification commands|pnpm run (lint|typecheck|build|test|test:e2e)|test:e2e' \
  AGENTS.md plan.md README.md docs frontend/package.json 2>/dev/null | head -160

Repository: ContextualWisdomLab/naruon

Length of output: 12955


Complete the PR validation evidence and literature citations.

Update plan.md so the PR body lists these exact commands and their results:

  • cd frontend && pnpm run lint
  • cd frontend && pnpm run typecheck
  • cd frontend && pnpm run build
  • cd frontend && pnpm run test
  • cd frontend && pnpm run test:e2e

For this substantive performance PR, add relevant academic citations, links, and short summaries. Commit paper PDFs only when redistribution is permitted.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plan.md` around lines 119 - 139, Update the validation and pre-commit
sections of plan.md to record each required command exactly—lint, typecheck,
build, test, and test:e2e from the frontend directory—along with its actual
result. Add relevant academic citations with links and brief summaries
supporting the performance optimization, and commit paper PDFs only when
redistribution is permitted; ensure the PR description reflects the completed
evidence and citations.

Source: Coding guidelines

Comment thread get_plan.py
@@ -0,0 +1,15 @@
import sys
@github-actions

Copy link
Copy Markdown
Contributor

PR governance metadata gate is not ready for 35c67ae9d3ac8c6a001bc5ed2dd717fb9566efac:

  • Review decision is CHANGES_REQUESTED; address requested changes before merge.
  • 3 unresolved current review thread(s) remain.

Copy link
Copy Markdown
Contributor Author

Superseded by #1342 after exact-diff review.

#1325's only product delta is the same NetworkGraph O(1) lookup conversion now preserved on current-develop PR #1342. #1342 additionally carries focused regression/performance coverage and excludes #1325's generated .jules/bolt.md, NetworkGraph.tsx.orig, get_plan.py, and plan.md artifacts. No unique production behavior from #1325 is being discarded. Closing this stale, non-mergeable branch to keep one canonical implementation owner; #1342 still must satisfy its own exact-head checks/review before merge.

@seonghobae seonghobae closed this Aug 14, 2026
@google-labs-jules

Copy link
Copy Markdown
Contributor

Superseded by #1342 after exact-diff review.

#1325's only product delta is the same NetworkGraph O(1) lookup conversion now preserved on current-develop PR #1342. #1342 additionally carries focused regression/performance coverage and excludes #1325's generated .jules/bolt.md, NetworkGraph.tsx.orig, get_plan.py, and plan.md artifacts. No unique production behavior from #1325 is being discarded. Closing this stale, non-mergeable branch to keep one canonical implementation owner; #1342 still must satisfy its own exact-head checks/review before merge.

Understood. Acknowledging that this work is now obsolete and stopping work on this task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant