Skip to content

⚡ Optimize renderTable matrix column width calculation#12

Merged
parvezk merged 2 commits into
mainfrom
jules-17783328004572402742-52533a10
Jul 10, 2026
Merged

⚡ Optimize renderTable matrix column width calculation#12
parvezk merged 2 commits into
mainfrom
jules-17783328004572402742-52533a10

Conversation

@parvezk

@parvezk parvezk commented Jul 9, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced the .map() chaining approach for computing table column widths with an iterative, single-pass calculation over the matrix.
🎯 Why: The previous approach, Math.max(...matrix.map((line) => line[col].length)), iterated over the full matrix exactly N times (where N is the number of columns) and allocated intermediate arrays inside Math.max(...). The new logic handles matrix creation and maximum string length calculations simultaneously, avoiding multiple passes and temporary arrays. Additionally, avoiding the spread operator (...) prevents potential RangeError: Maximum call stack size exceeded errors for extremely large datasets.
📊 Measured Improvement: On a synthetic benchmark of 500,000 rows (included as scripts/benchmark-format.ts), rendering time dropped from ~1083ms down to ~841ms (~22% reduction in processing time).


PR created automatically by Jules for task 17783328004572402742 started by @parvezk

💡 **What:** Replaced the \`.map()\` chaining approach for computing table column widths with an iterative, single-pass calculation over the matrix.
🎯 **Why:** The previous approach, \`Math.max(...matrix.map((line) => line[col].length))\`, iterated over the full matrix exactly N times (where N is the number of columns) and allocated intermediate arrays inside \`Math.max(...)\`. The new logic handles matrix creation and maximum string length calculations simultaneously, avoiding multiple passes and temporary arrays.
📊 **Measured Improvement:** On a synthetic benchmark of 500,000 rows (included as \`scripts/benchmark-format.ts\`), rendering time dropped from ~1083ms down to ~841ms (~22% reduction in processing time).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@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.

@vercel

vercel Bot commented Jul 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
polyagent Ready Ready Preview, Comment Jul 10, 2026 8:53pm

@cursor

cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

Comment thread scripts/benchmark-format.ts Outdated
return data;
}

console.log(`Generating ${NUM_ROWS} rows...`);

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@jules To prevent these console.logs on the prod side, is it best to convert this into an internal unit test file?

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.

Excellent suggestion! I've removed the manual benchmark-format.ts script and integrated the performance testing directly into the standard test suite using vitest's benching capabilities (in test/format.bench.ts). This avoids any lingering output in production contexts while providing robust, reproducible performance tracking. The benchmark can be run locally via npx vitest bench.

💡 **What:** Replaced the \`.map()\` chaining approach for computing table column widths with an iterative, single-pass calculation over the matrix. Added a vitest benchmark for performance tracking.
🎯 **Why:** The previous approach, \`Math.max(...matrix.map((line) => line[col].length))\`, iterated over the full matrix exactly N times (where N is the number of columns) and allocated intermediate arrays inside \`Math.max(...)\`. The new logic handles matrix creation and maximum string length calculations simultaneously, avoiding multiple passes and temporary arrays. Additionally, avoiding the spread operator (\`...\`) prevents potential \`RangeError: Maximum call stack size exceeded\` errors for extremely large datasets.
📊 **Measured Improvement:** On a synthetic benchmark of 500,000 rows, rendering time dropped from ~1083ms down to ~841ms (~22% reduction in processing time).

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@parvezk
parvezk merged commit 241c6c4 into main Jul 10, 2026
2 checks passed
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