Skip to content

⚡ Bolt: [성능 개선] FK 핸들 조회를 위한 O(1) Map 사전 계산#621

Open
seonghobae wants to merge 1 commit into
mainfrom
jules-13830521143332622645-f8a1a52d
Open

⚡ Bolt: [성능 개선] FK 핸들 조회를 위한 O(1) Map 사전 계산#621
seonghobae wants to merge 1 commit into
mainfrom
jules-13830521143332622645-f8a1a52d

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What:
exportDDL에서 테이블 컬럼 정보를 조회하여 O(1) 해시 맵(columnByHandle)을 생성하고 이를 fkColumnsForEdge에 전달하도록 변경했습니다. 또한, fkColumnsForEdge 내부의 배열 체이닝(.filter().map(), .find())을 단일 반복문(for) 및 O(1) Map 조회로 대체했습니다.

🎯 Why:
기존 방식은 그래프의 간선(Edges, $E$)마다 각 노드의 컬럼($C$)을 배열 체이닝이나 .find()로 검색하므로 $O(E \times C)$의 시간 복잡도와 불필요한 가비지 컬렉션 부담이 발생했습니다. O(1) 조회와 단일 반복문으로 변경하면 큰 다이어그램 내보내기에서 성능이 크게 개선됩니다.

📊 Impact:
간선 처리 루프 내 배열 탐색이 O(C)에서 O(1)로 단축됩니다. 중간 배열 할당이 제거되어 메모리 압박이 감소하고 큰 스키마 DDL 내보내기 성능이 향상됩니다.

🔬 Measurement:
프론트엔드 유닛 테스트(Vitest) 및 TypeScript 빌드가 정상 작동함을 확인했습니다. 엣지 테스트(coverageEdges.test.ts)가 성공적으로 통과합니다.


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

💡 What:
`exportDDL`에서 테이블 컬럼 정보를 조회하여 O(1) 해시 맵(`columnByHandle`)을 생성하고 이를 `fkColumnsForEdge`에 전달하도록 변경했습니다. 또한, `fkColumnsForEdge` 내부의 배열 체이닝(`.filter().map()`, `.find()`)을 단일 반복문(`for`) 및 O(1) Map 조회로 대체했습니다.

🎯 Why:
기존 방식은 그래프의 간선(Edges, $E$)마다 각 노드의 컬럼($C$)을 배열 체이닝이나 `.find()`로 검색하므로 $O(E \times C)$의 시간 복잡도와 불필요한 가비지 컬렉션 부담이 발생했습니다. O(1) 조회와 단일 반복문으로 변경하면 큰 다이어그램 내보내기에서 성능이 크게 개선됩니다.

📊 Impact:
간선 처리 루프 내 배열 탐색이 O(C)에서 O(1)로 단축됩니다. 중간 배열 할당이 제거되어 메모리 압박이 감소하고 큰 스키마 DDL 내보내기 성능이 향상됩니다.

🔬 Measurement:
프론트엔드 유닛 테스트(Vitest) 및 TypeScript 빌드가 정상 작동함을 확인했습니다. 엣지 테스트(`coverageEdges.test.ts`)가 성공적으로 통과합니다.
@google-labs-jules

Copy link
Copy Markdown

👋 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.

Copilot AI review requested due to automatic review settings July 22, 2026 13:54

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes foreign-key column resolution during ERD DDL export by precomputing a handle→column lookup map and replacing per-edge array searches with O(1) map lookups and single-pass loops, targeting better performance on large diagrams.

Changes:

  • Added optional columnByHandle Map support to fkColumnsForEdge and switched handle-based resolution to O(1) lookups when provided.
  • Precomputed columnByHandle inside exportDDL while building nodesById, and passed it into fkColumnsForEdge.
  • Replaced .filter().map() fallback column collection with single-pass loops to reduce allocations/GC pressure.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
frontend/src/erd/export.ts Adds precomputed handle→column Map and uses it to speed up FK column resolution in exportDDL.
.jules/bolt.md Documents the Bolt performance lesson learned and guidance around Map precomputation scope/guards.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 122 to 134
// Bolt: Use map for O(1) node lookup instead of O(N) array find
// Avoid Map(array.map) to prevent O(N) intermediate tuple array allocation overhead
const nodesById = new Map<string, Node<TableNodeData>>();
const columnByHandle = new Map<string, string>();
for (const n of nodes) {
nodesById.set(n.id, n);
for (const c of n.data.columns || []) {
if (c && c.column_name) {
columnByHandle.set(`${n.id}:${sourceColumnHandleId(c.column_name)}`, c.column_name);
columnByHandle.set(`${n.id}:${targetColumnHandleId(c.column_name)}`, c.column_name);
}
}
}
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.

2 participants