Skip to content

⚡ Bolt: Optimize ERD edge column resolution to O(1) using reverse-parsing - #647

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

⚡ Bolt: Optimize ERD edge column resolution to O(1) using reverse-parsing#647
seonghobae wants to merge 1 commit into
mainfrom
bolt-handle-parsing-12133381397972216538

Conversation

@seonghobae

Copy link
Copy Markdown
Collaborator

💡 What:
Introduced a parseColumnNameFromHandle utility to directly extract the original column name from hex-encoded src-c-* or tgt-c-* React Flow handles. Refactored the ERD export methods (exportDDL, exportDbml, exportMermaid, exportDataDictionary) to use this direct parsing utility instead of dynamically re-generating strings and iterating through the column list of the node.

🎯 Why:
During exports involving many nodes and edges, resolving a foreign key connection required iterating through all columns of a source or target table and generating encoded handles for every single column to see which one matched the incoming edge (O(E * C) worst case). This caused a large amount of array allocation and heavy string transformation within tight loops. The handles actually natively carry the hex-encoded column name. Reverse parsing transforms this back into an O(1) string decoding process, completely removing the array looping bottlenecks.

📊 Impact:

  • Replaces O(N) array scans with O(1) string parsing for all Edge handle resolutions.
  • Vastly reduces intermediary string garbage collection during heavy ERD export flows.
  • Fixes DBML output falling back to emitting internal encoded handles directly.

🔬 Measurement:

  1. Load a diagram containing 50-100 edges.
  2. Select "Export" -> "Mermaid" or "DBML".
  3. The underlying process will avoid thousands of redundant string iterations, allocating and executing immediately with correct column extraction.
  4. Unit tests pass cleanly, explicitly testing boundary parsing.

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

Added `parseColumnNameFromHandle` to directly reverse-engineer original column
names from the encoded React Flow connection strings. Replaced all O(N*C) node
column iterative matching searches inside ERD export builders (DBML, DDL,
Mermaid, and Data Dictionary) with the O(1) direct decode strategy.
@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 26, 2026 14:04
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@seonghobae, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 38 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 72a82dca-636a-430d-a8a2-f86c14814130

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf3968 and 55e3155.

📒 Files selected for processing (6)
  • .jules/bolt.md
  • frontend/src/erd/dbml.ts
  • frontend/src/erd/export.ts
  • frontend/src/erd/exportDataDictionary.ts
  • frontend/src/erd/handleUtils.test.ts
  • frontend/src/erd/handleUtils.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bolt-handle-parsing-12133381397972216538

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

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-time foreign key (FK) column resolution by decoding column names directly from React Flow handle IDs (hex-encoded), avoiding per-edge scans over table columns and reducing intermediate string allocations in large diagrams.

Changes:

  • Added parseColumnNameFromHandle to reverse-decode src-c-* / tgt-c-* (and c-*) handles back into raw column names.
  • Refactored FK column resolution in export flows to prefer direct handle parsing, with fallbacks to prior lookup behavior.
  • Updated handle utility tests and documented the performance lesson in .jules/bolt.md.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
frontend/src/erd/handleUtils.ts Adds reverse parsing utility to decode column names from handle IDs.
frontend/src/erd/handleUtils.test.ts Updates tests for new parsing behavior and existing handle encoding helpers.
frontend/src/erd/exportDataDictionary.ts Uses parsed source-handle column names to mark FK columns without per-column handle regeneration.
frontend/src/erd/export.ts Uses parsed handle decoding in fkColumnsForEdge to avoid O(columns) scans for common cases.
frontend/src/erd/dbml.ts Fixes DBML relationship emission to use decoded column names instead of internal handle strings.
.jules/bolt.md Records the optimization approach and rationale for future reference.

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

Comment on lines +19 to +31
const match = handleId.match(/^(?:src-|tgt-)?c-(.+)$/);
if (!match) return null;
const encoded = match[1];
if (encoded === 'empty') return '';

try {
return encoded
.split('-')
.map((hex) => String.fromCodePoint(parseInt(hex, 16)))
.join('');
} catch (e) {
return null;
}
Comment on lines +42 to +46
test('parses naked handle correctly', () => {
expect(parseColumnNameFromHandle('c-0075-0073-0065-0072-005f-0069-0064')).toBe('user_id');
});

describe('sourceColumnHandleId', () => {
it('should prepend src- to sanitized id', () => {
expect(sourceColumnHandleId('id')).toBe('src-c-0069-0064');
});
test('returns empty string for c-empty', () => {
@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