Skip to content

⚡ Bolt: Optimize ERD edge handle column parsing - #641

Closed
seonghobae wants to merge 1 commit into
mainfrom
bolt-erd-handle-parsing-10260667443787725602
Closed

⚡ Bolt: Optimize ERD edge handle column parsing#641
seonghobae wants to merge 1 commit into
mainfrom
bolt-erd-handle-parsing-10260667443787725602

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What:
Introduced a new O(1) utility function parseColumnNameFromHandle to extract the original column name directly from the React Flow edge handles (e.g., src-c-0069-0064), and applied it across all the ERD export functions (export.ts, dbml.ts, mermaid.ts, exportDataDictionary.ts).

🎯 Why:
Previously, to resolve which column an edge was connected to, the export logic had to iterate through all columns on a node and run the expensive sanitizeHandleId encoding function on every single one until it found a match against the edge handle (an O(N * C) search). Additionally, the DBML export had a silent bug where it was just doing .replace('src-', '') and accidentally exporting the raw hex string (c-0069-0064) into the DBML schema instead of the real column name.

📊 Impact:

  • Reduces time complexity of resolving edge columns from O(N * C) to O(1) per edge.
  • Eliminates heavy string manipulation and array allocations inside nested loops during export.
  • Fixes DBML edge fallback column name bug for relationships with missing metadata.

🔬 Measurement:

  • All ERD export tests (coverageEdges.test.ts, export.test.ts, dbml.test.ts, mermaid.test.ts) were executed and pass, with updated mocks confirming the DBML bugfix.

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

This commit introduces a new `parseColumnNameFromHandle` utility function
that decodes edge handle IDs directly into column names in O(1) time.
Previously, export functions like DBML, Mermaid, and Data Dictionary were
using O(N * C) loops that repeatedly re-encoded every column in the entire
table to find a match. This significantly reduces CPU overhead and garbage
collection during export of large diagrams.
Copilot AI review requested due to automatic review settings July 25, 2026 14:30
@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.


import type { ForeignKeyEdgeData, TableNodeData } from './convert';
import { sourceColumnHandleId } from './handleUtils';
import { parseColumnNameFromHandle, sourceColumnHandleId } from './handleUtils';
import type { Node, Edge } from "@xyflow/react";
import type { TableNodeData } from "./convert";
import { sanitizeHandleId } from "./handleUtils";
import { parseColumnNameFromHandle, sanitizeHandleId } 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

This PR optimizes ERD export logic by decoding React Flow handle IDs back into original column names via a new utility (parseColumnNameFromHandle), avoiding repeated handle-encoding scans and fixing DBML fallback behavior when edge metadata is missing.

Changes:

  • Added parseColumnNameFromHandle to decode src-/tgt- handle IDs (e.g. src-c-0069-0064) back to the original column name.
  • Refactored Mermaid / Data Dictionary / DDL export column resolution to use decoded column names rather than re-encoding every column for comparisons.
  • Updated/expanded export and handle utility tests and documented the optimization in .jules/bolt.md.

Reviewed changes

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

Show a summary per file
File Description
frontend/src/erd/mermaid.ts Uses decoded handle column names to build FK lookups during Mermaid export.
frontend/src/erd/handleUtils.ts Introduces parseColumnNameFromHandle for O(1) decode of handle IDs.
frontend/src/erd/handleUtils.test.ts Adds unit tests covering handle decoding (ascii/unicode/emoji/empty).
frontend/src/erd/exportDataDictionary.ts Simplifies FK column detection to use decoded handle columns.
frontend/src/erd/export.ts Updates FK column resolution for DDL/export paths to use decoded handles.
frontend/src/erd/dbml.ts Fixes DBML fallback to output real decoded column names from handles.
frontend/src/erd/tests/dbml.test.ts Updates DBML tests to use encoded handle IDs.
frontend/src/erd/tests/coverageEdges.test.ts Updates defensive coverage tests for encoded handles / empty-handle cases.
.jules/bolt.md Records the performance learning/action for handle decoding optimization.

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

Comment on lines +1 to +8
export function parseColumnNameFromHandle(handleId: string | null | undefined): string | null {
if (!handleId) return null;
const match = handleId.match(/^(?:src-|tgt-)?c-(.+)$/);
if (!match) return null;
const encoded = match[1];
if (encoded === 'empty') return '';
return encoded.split('-').map(hex => String.fromCodePoint(parseInt(hex, 16))).join('');
}
Comment on lines 1 to +3
import type { Node, Edge } from "@xyflow/react";
import type { TableNodeData } from "./convert";
import { sanitizeHandleId } from "./handleUtils";
import { parseColumnNameFromHandle, sanitizeHandleId } from "./handleUtils";
Comment on lines 3 to 5
import type { ForeignKeyEdgeData, TableNodeData } from './convert';
import { sourceColumnHandleId } from './handleUtils';
import { parseColumnNameFromHandle, sourceColumnHandleId } from './handleUtils';

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

2 participants