Skip to content

Windows performance optimizations: paste handling, shell compatibility, and message display#18314

Closed
devnezu wants to merge 5 commits into
google-gemini:mainfrom
devnezu:feature/windows-performance-optimizations
Closed

Windows performance optimizations: paste handling, shell compatibility, and message display#18314
devnezu wants to merge 5 commits into
google-gemini:mainfrom
devnezu:feature/windows-performance-optimizations

Conversation

@devnezu

@devnezu devnezu commented Feb 4, 2026

Copy link
Copy Markdown

Fixes #18366

Summary

This PR addresses three critical performance and compatibility issues on Windows that make Gemini CLI nearly unusable for real-world workflows:

  1. UI freeze on large paste operations - Implemented fast paste optimization with placeholder-based handling
  2. Terminal freeze when displaying large messages - Added message display truncation for chat history
  3. PowerShell command execution failures - Configured shell to prefer Git Bash on Windows

Changes

1. Fast Paste Handling (InputPrompt.tsx)

  • Detects large pastes (>500 characters)
  • Instantly displays placeholder like [Pasted Text: X chars]
  • Stores full content separately and substitutes on submission
  • Prevents O(n²) character-by-character buffer processing

2. Message Display Truncation (UserMessage.tsx)

  • Truncates display of messages >2000 characters or >50 lines
  • Shows preview with character/line counts
  • Full content still sent to model API
  • Prevents terminal rendering freeze

3. Git Bash Preference (shell-utils.ts)

  • Detects Git Bash installation on Windows via PATH search
  • Configures shell to use bash.exe for command execution
  • Falls back to PowerShell if Git Bash not found
  • Ensures AI-generated Unix commands work correctly

Testing

Extensively tested on Windows 11 with:

  • Pastes ranging from 500 to 467,935 characters
  • Chat history with multiple large messages
  • AI-generated commands using &&, ||, pipes
  • Both Git Bash and PowerShell environments

Backward Compatibility

All changes maintain full backward compatibility:

  • Fast paste only activates for large pastes (>500 chars)
  • Message truncation only affects visual display, not API payload
  • Shell detection gracefully falls back to PowerShell

Note: This PR has been updated to address code review feedback:

  • ✅ Fixed React state mutation by adding immutable addPastedContent() method
  • ✅ Improved Git Bash detection robustness with PATH-based search

Intercept large paste events (>500 chars) BEFORE buffer processing
to show placeholder text instantly. The full content is stored in
refs and correctly substituted on submit.

- Add fastPasteContentRef and fastPasteCounterRef for storage
- Intercept terminal paste events before buffer.handleInput()
- Intercept Ctrl+V paste before buffer.insert()
- Update handleSubmitAndClear to use combined content from refs
- Placeholders use existing [Pasted Text: X lines/chars] format
AI models predominantly generate bash/unix commands which fail on
PowerShell with syntax errors (e.g. && operator, bash builtins).
This change detects Git Bash installation and uses it as the
preferred shell on Windows, falling back to PowerShell if not found.

- Check common Git Bash installation paths
- Use bash with -c flag when found
- Maintain PowerShell fallback for systems without Git
Displaying messages with 50k+ characters causes terminal rendering
to freeze for several seconds. This change truncates the visual
display while still sending the full content to the model.

- Limit display to 2000 chars or 50 lines
- Show preview + character/line count for large messages
- Full content is still sent to the model API
- Prevents terminal UI freeze on large pastes
@devnezu devnezu requested a review from a team as a code owner February 4, 2026 16:39
@google-cla

google-cla Bot commented Feb 4, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @devnezu, 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 user experience on Windows by addressing critical performance and compatibility issues. It resolves UI freezes caused by large text pastes and extensive message displays, and improves the reliability of AI-generated commands by configuring the shell to prefer Git Bash. These changes collectively lead to a more responsive and functional application for Windows users.

Highlights

  • Fast Paste Handling: Implemented an optimization in InputPrompt.tsx to prevent UI freezes when pasting large amounts of text (over 500 characters). Instead of processing character by character, a placeholder like '[Pasted Text: X chars/lines]' is instantly displayed, and the full content is stored for later substitution upon submission.
  • Git Bash Preference on Windows: Modified shell-utils.ts to detect and prioritize Git Bash on Windows systems. This ensures that AI-generated commands, which often use Unix-like syntax (&&, ||), execute correctly by leveraging Bash, falling back to PowerShell if Git Bash is not found.
  • Message Display Truncation: Added truncation logic to UserMessage.tsx for very long chat messages (over 2000 characters or 50 lines). This prevents terminal rendering freezes by displaying a truncated preview with character/line counts, while the full message content is still sent to the model API.
Changelog
  • packages/cli/src/ui/components/InputPrompt.tsx
    • Introduced fastPasteContentRef and fastPasteCounterRef to manage large paste content efficiently.
    • Updated handleSubmitAndClear to retrieve paste content from both the buffer and the new fast paste refs, clearing the fast paste refs after use.
    • Implemented a fast paste optimization for both Ctrl+V and terminal paste events, displaying a placeholder for pastes exceeding 500 characters and storing the actual content in refs.
  • packages/cli/src/ui/components/messages/UserMessage.tsx
    • Added logic to truncate the display of user messages longer than 2000 characters or 50 lines, showing a concise preview and statistics to prevent terminal rendering issues.
  • packages/core/src/utils/shell-utils.ts
    • Modified getShellConfiguration to check for and prioritize Git Bash installations on Windows, configuring the shell to use bash.exe with the -c flag for command execution.
    • Ensured a graceful fallback to PowerShell if Git Bash is not detected on the system.
Activity
  • The author, devnezu, created this pull request to address common user complaints regarding UI responsiveness and command execution failures on Windows.
  • Extensive testing was performed on Windows 11, covering large pastes (500 to 467,935 characters), AI-generated commands with complex operators (&&, ||, pipes), and message history containing multiple large entries.
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 introduces several significant performance and usability improvements for Windows users. The fast paste optimization prevents UI freezes with large clipboard content, and message truncation in the chat history improves rendering performance. The change to prefer Git Bash for command execution is a great step towards better compatibility with AI-generated commands.

My review focuses on two main areas:

  1. A critical bug in the fast paste implementation where React state is mutated directly.
  2. A suggestion to improve the robustness of Git Bash detection to support more user environments.

Overall, these are valuable enhancements. Addressing the identified issues will make the new features more stable and reliable.

Comment on lines +425 to +426
if (!buffer.pastedContent) buffer.pastedContent = {};
buffer.pastedContent[placeholder] = textToInsert;

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.

critical

This is a direct mutation of the buffer.pastedContent state, which is a critical bug in React. State from hooks like useTextBuffer (which uses useReducer) should be treated as immutable and only updated via dispatching actions. Direct mutation can lead to unpredictable UI behavior, stale data, and bugs that are difficult to trace.

To fix this, you should expose a new method from the useTextBuffer hook (e.g., addPastedContent(id, text)) that properly dispatches an action to update the pastedContent state immutably.

Additionally, the logic for handling large pastes is duplicated in this file (here and at lines 571-572). This should be extracted into a single helper function to improve maintainability.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in commit 002d09f.

Changes made:

  • Added addPastedContent(id, text) method to TextBuffer that properly dispatches the add_pasted_content action
  • Extracted duplicate paste logic into handleLargePaste() helper function
  • Replaced all direct buffer.pastedContent mutations with buffer.addPastedContent() calls

The helper function now handles all large paste scenarios consistently and uses the proper React state management pattern.

Comment thread packages/core/src/utils/shell-utils.ts Outdated
Comment on lines +547 to +564
const gitBashPaths = [
'C:\\Program Files\\Git\\bin\\bash.exe',
'C:\\Program Files (x86)\\Git\\bin\\bash.exe',
`${process.env['PROGRAMFILES']}\\Git\\bin\\bash.exe`,
];
for (const bashPath of gitBashPaths) {
try {
if (fs.existsSync(bashPath)) {
return {
executable: bashPath,
argsPrefix: ['-c'],
shell: 'bash',
};
}
} catch {
// continue to next path
}
}

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.

high

The current implementation for detecting Git Bash on Windows relies on hardcoded paths. This approach is brittle and will fail for users who have installed Git in a custom location, which is a common scenario. This makes the feature unreliable.

A more robust approach would be to avoid hardcoded paths. Consider one of the following strategies:

  1. Check the PATH environment variable: Git for Windows often adds bash.exe's directory to the PATH. You could search for bash.exe in the directories listed in PATH.
  2. Find git.exe and derive the path: Locate git.exe using the PATH (e.g., by shelling out to where git), and then find bash.exe relative to its location (it's typically in a sibling bin directory or similar).
  3. Check the Windows Registry: The Git for Windows installer usually creates a registry key at HKLM\SOFTWARE\GitForWindows which contains the InstallPath.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fixed in commit 21ec0c0.

Implemented a robust multi-method detection strategy:

  1. Primary method: Search for bash.exe in PATH environment variable

    • Most reliable for any installation location
    • Validates it's Git Bash by checking if path contains 'git'
  2. Fallback method: Check common installation paths

    • Includes both PROGRAMFILES and PROGRAMFILES(X86) for 32-bit installs
    • Covers standard Git for Windows installation locations

This approach handles custom installations while maintaining the PowerShell fallback for systems without Git. The PATH-based detection should catch the vast majority of Git installations regardless of where users choose to install it.

@gemini-cli gemini-cli Bot added the status/need-issue Pull requests that need to have an associated issue. label Feb 4, 2026
Address code review feedback: Replace direct mutation of buffer.pastedContent
with proper React state management using the reducer pattern.

Changes:
- Add addPastedContent() method to TextBuffer interface
- Extract duplicate paste logic into handleLargePaste() helper
- Use buffer.addPastedContent() instead of direct mutation
- Maintain compatibility with existing pastedContent system

This fixes the critical bug where React state was being mutated directly,
which could lead to unpredictable UI behavior and stale data.
Address code review feedback: Hardcoded paths fail for users with custom
Git installation locations. Implement multi-method detection strategy:

1. Search for bash.exe in PATH environment variable (most reliable)
2. Verify it's Git Bash by checking path contains 'git'
3. Fall back to common installation paths
4. Include PROGRAMFILES(X86) for 32-bit installs

This ensures Git Bash is detected regardless of installation location
while maintaining PowerShell fallback for systems without Git.
@gemini-cli

gemini-cli Bot commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. Once you have updated the description of this PR to link an issue (e.g., by adding Fixes #123 or Related to #123), it will be automatically reopened.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details on supported keywords and how linking works, please refer to the GitHub Documentation on linking pull requests to issues.

Thank you for your understanding and for being a part of our community!

@devnezu

devnezu commented Feb 5, 2026

Copy link
Copy Markdown
Author

Hi! I've updated the PR description to link to issue #18366 as requested. The PR should now be automatically reopened according to the bot's message. Thanks!

@sripasg sripasg added the size/m A medium sized PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m A medium sized PR status/need-issue Pull requests that need to have an associated issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Windows] Critical performance issues: UI freeze on paste, terminal freeze on display, and PowerShell command failures

2 participants