Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

abhipatel12
Copy link
Collaborator

TLDR

This PR optimizes the IDE process detection logic on Windows, reducing CLI slash command loading time from ~30 seconds to ~1.6 seconds. It replaces an iterative, multi-process approach with a single snapshot approach, resolving a bottleneck that caused flaky integration tests (fixes #11037, contributes to #10769). This also helps alleviate the long delay Windows users faced when attempting to quit the application (due to slash commands not being loaded).

Dive Deeper

The Problem

On Windows, getIdeProcessInfo previously attempted to find the IDE process by walking up the process tree, spawning a new PowerShell instance for every ancestor to query Win32_Process. Since PowerShell startup is relatively slow, this resulted in an $O(N)$ operation taking roughly 30 seconds for a typical process depth. This delay caused race conditions in integration tests where commands were not fully loaded before tests began.

The Solution

The implementation in packages/core/src/ide/process-utils.ts has been changed to use an $O(1)$ snapshot approach for Windows:

  1. Execute a single PowerShell command to retrieve ProcessId, ParentProcessId, Name, and CommandLine for all system processes as JSON.
  2. Parse the JSON into an in-memory Map.
  3. Perform the tree traversal logic within Node.js using the Map.

Performance Impact

Based on local profiling:

  • Windows: IDE detection time reduced from ~29.8s to ~1.6s.
  • macOS/Linux: Logic remains unchanged; performance remains fast (~180ms).

Unit tests in process-utils.test.ts have been updated to mock the single snapshot output rather than individual process lookups.

Reviewer Test Plan

  1. Unit Tests: Run npm run test --workspace=@google/gemini-cli-core to ensure the new logic and mocks are correct.
  2. Windows Verification:
    • Run the CLI on a Windows machine from an integrated terminal (e.g., VS Code).
    • Run /ide status.
    • Observe that the command correctly identifies the connected IDE.
  3. Unix Verification:
    • Run the CLI on macOS or Linux.
    • Run /ide status.
    • Ensure functionality remains unchanged and fast.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

@abhipatel12 abhipatel12 requested a review from a team as a code owner October 13, 2025 18:31
Copy link
Contributor

Summary of Changes

Hello @abhipatel12, 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 delivers a critical performance enhancement for Windows users by overhauling the IDE process detection mechanism. Previously, the system suffered from significant delays and instability due to an inefficient, iterative method of querying process information. The new implementation introduces a highly optimized, single-query snapshot approach, which dramatically cuts down the time required to identify the IDE process, leading to a more responsive application and more reliable integration tests.

Highlights

  • Performance Optimization: The Windows IDE process detection logic has been optimized from an O(N) iterative approach to an O(1) snapshot-based approach, drastically reducing loading times.
  • Speed Improvement: IDE detection time on Windows is reduced from approximately 30 seconds to 1.6 seconds, resolving a major bottleneck.
  • Stability Fix: This change addresses flaky integration tests caused by the previous slow process detection and alleviates delays for Windows users when quitting the application.
  • Implementation Details: The new approach executes a single PowerShell command to retrieve all process information as JSON, which is then parsed into an in-memory Map for efficient tree traversal within Node.js.
  • Test Updates: Unit tests for process-utils.test.ts have been updated to mock the single snapshot output, reflecting the new logic.
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.

@abhipatel12 abhipatel12 requested a review from jacob314 October 13, 2025 18:31
Copy link

Size Change: +93 B (0%)

Total Size: 17.8 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 17.8 MB +93 B (0%)
./bundle/sandbox-macos-permissive-closed.sb 1.03 kB 0 B
./bundle/sandbox-macos-permissive-open.sb 830 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

Copy link
Contributor

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

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 a significant performance optimization for IDE process detection on Windows by switching from an iterative, multi-process approach to a single process snapshot. This is a great improvement that should resolve the long delays and test flakiness. My review focuses on increasing the robustness of this new implementation. I've suggested adding logging to error-handling blocks that currently fail silently, which will make debugging much easier. I also found a small piece of unreachable code in the new process traversal logic and suggested a simplification. The updated tests look thorough and cover the new logic well.

packages/core/src/ide/process-utils.ts Show resolved Hide resolved
Comment on lines +69 to +71
} catch (_e) {
// Fallback or error handling if PowerShell fails
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

Similar to the JSON parsing, this catch block silences errors from executing the PowerShell command. Logging these errors is crucial for diagnosing environment-specific problems, such as PowerShell not being in the PATH or permission issues. Please log the error to aid in troubleshooting.

Suggested change
} catch (_e) {
// Fallback or error handling if PowerShell fails
}
} catch (e) {
// Fallback or error handling if PowerShell fails
console.debug('Failed to get process list from PowerShell:', e);
}

Comment on lines 104 to 106
} catch (_e) {
console.debug(`Failed to get process info for pid ${pid}:`, _e);
return { parentPid: 0, name: '', command: '' };
}
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The console.debug call was removed from this catch block. While this function is expected to fail on Windows when used as a fallback, it's the primary method for Unix systems. Silently catching errors on Unix could make it difficult to debug why IDE detection is failing. Please consider re-adding the error logging.

  } catch (e) {
    console.debug(`Failed to get process info for pid ${pid}:`, e);
    return { parentPid: 0, name: '', command: '' };
  }

Comment on lines +195 to +200
} else if (ancestors.length > 0) {
const target = ancestors[ancestors.length - 1];
return { pid: target.pid, command: target.command };
}

return { pid: myPid, command: myProc.command };
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The final return statement on line 200 appears to be unreachable. If myProc is defined, the ancestors array will always have at least one element, so the condition ancestors.length > 0 on line 195 will always be true, causing one of the branches in the if/else if to execute and return. This can be simplified by removing the unreachable code and the redundant check.

  } else {
    // For shorter chains, fall back to the root-most ancestor.
    const target = ancestors[ancestors.length - 1];
    return { pid: target.pid, command: target.command };
  }

Copy link
Collaborator

@scidomino scidomino left a comment

Choose a reason for hiding this comment

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

I ran this on my windows machine and verified that it speeds things up a lot.

@abhipatel12 abhipatel12 added this pull request to the merge queue Oct 14, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 14, 2025
@abhipatel12 abhipatel12 added this pull request to the merge queue Oct 14, 2025
Merged via the queue into main with commit 6787d42 Oct 14, 2025
20 checks passed
@abhipatel12 abhipatel12 deleted the abhipatel12/optimize-windows-process-detection branch October 14, 2025 02:56
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.

Optimize Windows IDE Process Detection

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.