Skip to content

⚡ Bolt: ERD Export 시 O(N*C) 문자열 인코딩 병목을 O(1) 디코딩으로 최적화 - #634

Closed
seonghobae wants to merge 1 commit into
mainfrom
bolt/optimize-export-handle-decoding-13004221925778527541
Closed

⚡ Bolt: ERD Export 시 O(N*C) 문자열 인코딩 병목을 O(1) 디코딩으로 최적화#634
seonghobae wants to merge 1 commit into
mainfrom
bolt/optimize-export-handle-decoding-13004221925778527541

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What:
ERD Export 로직과 Data Dictionary 내보내기 로직에서 각 컬럼 이름과 핸들(Handle) 간의 매칭을 수행할 때 발생하던 불필요한 비용을 줄였습니다. 기존에는 모든 컬럼에 대해 매번 sourceColumnHandleId (문자열 인코딩)를 수행한 후 검색을(find()) 했지만, 개선된 방식에서는 핸들을 단 1번 원본 텍스트로 **디코딩(Decoding)**한 후 O(1) 해시나 단순 일치 검사를 수행하도록 변경했습니다.

🎯 Why:
fkColumnsForEdgeforeignKeyColumnsByNode 함수는 그래프 노드를 순회하며 각각의 Edge와 연결된 Column을 찾습니다. 여기서 매번 전체 Column(C)들을 순회(N)하며 16진수 문자열 인코딩(charCodeAt & padStart)을 수행하면, 테이블 및 컬럼 수와 엣지가 많아질수록 심각한 성능 저하와 가비지 컬렉터 부하를 발생시킵니다 (O(N*C) String Processing).

📊 Impact:

  • ERD 내보내기 및 딕셔너리 생성 시의 CPU 처리 시간이 크게 줄어듭니다.
  • 불필요한 단기 객체(String, Array) 생성이 감소하여 GC(가비지 컬렉션) 지연 현상이 해결됩니다.

🔬 Measurement:

  • 다수의 컬럼(수백 개)과 관계(수십 개)가 연결된 ERD 다이어그램 캔버스를 열고 Data Dictionary Export 버튼을 눌러 소요 시간을 측정하면 성능 향상을 확인할 수 있습니다.
  • pnpm run test --coverage 를 통해 테스트 스위트가 여전히 100%를 달성하는지 확인 완료했습니다.

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

* frontend/src/erd/handleUtils.ts: `decodeHandleId`, `decodeSourceHandleId`, `decodeTargetHandleId`를 추가하여 인코딩된 문자열을 기존 컬럼명으로 바로 복원할 수 있도록 지원.
* frontend/src/erd/export.ts, exportDataDictionary.ts: `fkColumnsForEdge`와 `foreignKeyColumnsByNode` 등에서 O(C) 인코딩 `.find()` 스캔 대신 O(1) 핸들 디코딩을 사용하여 성능을 대폭 개선.
* frontend/src/erd/handleUtils.test.ts: 디코딩 함수들에 대한 100% 테스트 커버리지 달성.
@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 24, 2026 21:42
Comment on lines +5 to +10
import {
decodeSourceHandleId,
decodeTargetHandleId,
sourceColumnHandleId,
targetColumnHandleId,
} from './handleUtils';

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

Optimizes ERD export and Data Dictionary export by avoiding repeated per-column handle encoding work when resolving FK columns from React Flow edge handles, reducing string/GC overhead for large schemas.

Changes:

  • Added handle decoding helpers (decodeHandleId, decodeSourceHandleId, decodeTargetHandleId) to recover original column names from handle IDs.
  • Updated FK-column resolution in export.ts and exportDataDictionary.ts to decode edge handles once and match by column name / Set membership.
  • Expanded unit tests for the new decode helpers and documented the “Bolt” performance learning.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frontend/src/erd/handleUtils.ts Adds decoding utilities for handle IDs to avoid repeated encoding work during exports.
frontend/src/erd/handleUtils.test.ts Adds unit tests covering decode helpers (ASCII, unicode, emoji, invalid prefix).
frontend/src/erd/exportDataDictionary.ts Precomputes per-node FK column name Sets using decoded source handles for faster lookups during dictionary export.
frontend/src/erd/export.ts Uses decoded edge handles to resolve single-column FK mappings without re-encoding each candidate column.
.jules/bolt.md Records the performance rationale and approach for the optimization.

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

Comment on lines +18 to +26
export function decodeHandleId(encoded: string): string {
if (encoded === 'c-empty') return ''
if (!encoded.startsWith('c-')) return ''
return encoded
.slice(2)
.split('-')
.map((hex) => String.fromCodePoint(parseInt(hex, 16)))
.join('')
}
Comment on lines +5 to +10
import {
decodeSourceHandleId,
decodeTargetHandleId,
sourceColumnHandleId,
targetColumnHandleId,
} from './handleUtils';
Comment on lines +75 to +76
// ⚡ Bolt: Decode O(1) edge handle strings directly into column names and strictly match them,
// replacing expensive O(C) string conversions and matching loops with O(1) checks.
@seonghobae

Copy link
Copy Markdown
Collaborator Author

Closed as superseded/duplicate agent perf micro-optimization; main already has comparable Bolt export/render opts (#561/#538). Commercial-baseline drain: not uniquely required.

@seonghobae seonghobae closed this Jul 31, 2026
@google-labs-jules

Copy link
Copy Markdown

Closed as superseded/duplicate agent perf micro-optimization; main already has comparable Bolt export/render opts (#561/#538). Commercial-baseline drain: not uniquely required.

Understood. Acknowledging that this work is superseded by changes already in main and is now obsolete. 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.

2 participants