Windows performance optimizations: paste handling, shell compatibility, and message display#18314
Conversation
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
|
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. |
Summary of ChangesHello @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
Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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:
- A critical bug in the fast paste implementation where React state is mutated directly.
- 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.
| if (!buffer.pastedContent) buffer.pastedContent = {}; | ||
| buffer.pastedContent[placeholder] = textToInsert; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Fixed in commit 002d09f.
Changes made:
- Added
addPastedContent(id, text)method toTextBufferthat properly dispatches theadd_pasted_contentaction - Extracted duplicate paste logic into
handleLargePaste()helper function - Replaced all direct
buffer.pastedContentmutations withbuffer.addPastedContent()calls
The helper function now handles all large paste scenarios consistently and uses the proper React state management pattern.
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
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:
- Check the
PATHenvironment variable: Git for Windows often addsbash.exe's directory to thePATH. You could search forbash.exein the directories listed inPATH. - Find
git.exeand derive the path: Locategit.exeusing thePATH(e.g., by shelling out towhere git), and then findbash.exerelative to its location (it's typically in a siblingbindirectory or similar). - Check the Windows Registry: The Git for Windows installer usually creates a registry key at
HKLM\SOFTWARE\GitForWindowswhich contains theInstallPath.
There was a problem hiding this comment.
Fixed in commit 21ec0c0.
Implemented a robust multi-method detection strategy:
-
Primary method: Search for
bash.exein PATH environment variable- Most reliable for any installation location
- Validates it's Git Bash by checking if path contains 'git'
-
Fallback method: Check common installation paths
- Includes both
PROGRAMFILESandPROGRAMFILES(X86)for 32-bit installs - Covers standard Git for Windows installation locations
- Includes both
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.
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.
|
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 How to link an issue: Thank you for your understanding and for being a part of our community! |
|
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! |
Fixes #18366
Summary
This PR addresses three critical performance and compatibility issues on Windows that make Gemini CLI nearly unusable for real-world workflows:
Changes
1. Fast Paste Handling (
InputPrompt.tsx)[Pasted Text: X chars]2. Message Display Truncation (
UserMessage.tsx)3. Git Bash Preference (
shell-utils.ts)bash.exefor command executionTesting
Extensively tested on Windows 11 with:
&&,||, pipesBackward Compatibility
All changes maintain full backward compatibility:
Note: This PR has been updated to address code review feedback:
addPastedContent()method