Skip to content

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

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

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

Conversation

@devnezu
Copy link
Copy Markdown

@devnezu devnezu commented Feb 5, 2026

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
  • Uses immutable state updates via addPastedContent() method

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 via PATH environment variable search
  • Verifies bash.exe is from Git installation
  • Configures shell to use bash.exe for command execution
  • Falls back to common installation paths and PowerShell
  • 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
  • Custom Git installation paths

Implementation Details

Fast Paste Implementation:

  • Created handleLargePaste() helper function to eliminate code duplication
  • Added addPastedContent() method to TextBuffer for immutable state updates
  • Handles both Ctrl+V and terminal paste events

Git Bash Detection:

  • Primary method: Searches PATH environment variable for bash.exe
  • Validation: Confirms bash.exe path contains 'git' to avoid WSL bash
  • Fallback: Checks common paths including PROGRAMFILES(X86) for 32-bit installs
  • Graceful degradation to PowerShell if Git Bash not found

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
  • No breaking changes to existing functionality

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
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.
@devnezu devnezu requested a review from a team as a code owner February 5, 2026 10:59
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the summary. You can try again by commenting /gemini summary.

@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli bot commented Mar 8, 2026

Hi there! Thank you for your contribution to Gemini CLI. We really appreciate the time and effort you've put into this pull request.

To keep our backlog manageable and ensure we're focusing on current priorities, we are closing pull requests that haven't seen maintainer activity for 30 days. Currently, the team is prioritizing work associated with 🔒 maintainer only or help wanted issues.

If you believe this change is still critical, please feel free to comment with updated details. Otherwise, we encourage contributors to focus on open issues labeled as help wanted. Thank you for your understanding!

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

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

1 participant