Skip to content

perf(ui): optimize table rendering by memoizing styled characters - #18770

Merged
devr0306 merged 4 commits into
mainfrom
optimize-table-rendering
Feb 11, 2026
Merged

perf(ui): optimize table rendering by memoizing styled characters#18770
devr0306 merged 4 commits into
mainfrom
optimize-table-rendering

Conversation

@devr0306

@devr0306 devr0306 commented Feb 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Precomputed styled headers and rows instead of computing them multiple times.
Also fixed an edge case where lesser headers than rows would cause a runtime crash.

Details

Made toStyledChars get called only once in the beginning instead of multiple times and memoized the values for styled rows and headers.
Stopped using headers.length to get column count and using the max of headers and rows.

Related Issues

Fixes #18763

How to Validate

Run the tests in TableRenderer.test.tsx: npm test -w @google/gemini-cli -- src/ui/utils/TableRenderer.test.tsx . They should all pass.

Manual testing:
Ask Gemini to generate a table with long columns

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@devr0306
devr0306 requested a review from a team as a code owner February 10, 2026 21:46
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @devr0306, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the performance of the TableRenderer component by implementing memoization for styled headers and rows. By precomputing these values, it eliminates redundant and computationally intensive calls to toStyledCharacters, leading to a more efficient and faster rendering process for tables. This change directly addresses and fixes issue #18763.

Highlights

  • Performance Optimization: Optimized table rendering by precomputing styled headers and rows, reducing redundant calls to toStyledCharacters.
  • Memoization: Implemented useMemo for styledHeaders and styledRows to cache their values and prevent re-computation.
  • Refactored calculateWidths: Modified the calculateWidths function to directly accept StyledChar[] instead of a raw string, leveraging the precomputed styled characters.
Changelog
  • packages/cli/src/ui/utils/TableRenderer.tsx
    • Modified the calculateWidths function signature to accept StyledChar[] directly, removing an internal call to toStyledCharacters.
    • Introduced styledHeaders and styledRows using useMemo to pre-process all header and cell content into StyledChar[] arrays.
    • Updated the logic within the main useMemo hook to utilize these precomputed styledHeaders and styledRows for constraint calculation and wrapping.
    • Adjusted the dependency array of the main useMemo hook to reflect the new styledHeaders and styledRows dependencies.
Activity
  • The pull request was created by devr0306.
  • It addresses and fixes issue Optimize table rendering #18763.
  • No further human activity (comments, reviews) has been recorded yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request effectively optimizes the table rendering by pre-computing and memoizing styled characters for headers and rows, which prevents expensive re-calculations. I've identified one critical edge case where providing empty headers could lead to a runtime crash, and I've provided a suggestion to fix it. Additionally, I've noted an area for improvement in space distribution logic based on repository guidelines.

@github-actions

github-actions Bot commented Feb 10, 2026

Copy link
Copy Markdown

Size Change: +512 B (0%)

Total Size: 24.3 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.3 MB +512 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-closed.sb 3.29 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B

compressed-size-action

@gemini-cli gemini-cli Bot added area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 10, 2026
@devr0306 devr0306 changed the title Optimized table rendering by reducing expensive calls perf(ui): optimize table rendering by memoizing styled characters Feb 10, 2026

@jacob314 jacob314 left a comment

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.

lgtm

@devr0306
devr0306 added this pull request to the merge queue Feb 11, 2026
Merged via the queue into main with commit 63e9d5d Feb 11, 2026
27 checks passed
@devr0306
devr0306 deleted the optimize-table-rendering branch February 11, 2026 13:19
kuishou68 pushed a commit to iOfficeAI/gemini-cli-pro that referenced this pull request Feb 27, 2026
@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
software-0ficial pushed a commit to software-0ficial/gemini-cli that referenced this pull request Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize table rendering

3 participants