Skip to content

Optimize PowerShell availability check: file existence fast path with automatic recovery#2596

Open
Copilot wants to merge 13 commits intomainfrom
copilot/optimize-powershell-validation
Open

Optimize PowerShell availability check: file existence fast path with automatic recovery#2596
Copilot wants to merge 13 commits intomainfrom
copilot/optimize-powershell-validation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 3, 2026

Human PR description by @nagilson:

Summary

Powershell is often not found / resolved properly on machines. This happens for about 6% of our (windows) customers.
Before, we resolved which powershell path worked before we ran the install script.

Prior Code:

  1. Try powershell.exe (94% success rate)
  2. try full path to powershell (18% success rate, so about 95% now)
  3. try pwsh (1.3% success rate, so about 96.3% now)
  4. It used to try pwsh.exe which had 0% success rate, waste of time
  5. same with powershell, 0%, waste
  6. then run install script

Now:

We check if the file exists and run with the hard-coded powershell path without trying to verify powershell 'works' first, then fall back to checking for a working powershell and retry with that once.

file exists check median: ~0.2–1.4 ms
prior powershell.exe check median (on success): 335.1 ms
new full path exe check median ( on success): 75 ms

What this means:

  1. We save 594 ms (335 ms - 1 ms for file check PLUS the 260 ms differential on using the full path invocation ) ms on windows for all .NET acquisitions per median user for ~94% (<- I don't have data on who the full path works for but the powershell.exe path does work for, so this is approximate, but in general it seems to be more reliable) of customers with this change.
  2. We save 6 ms for failure cases by eliminating extra checks (failure cases median only 1-4 ms) for those 3.7% of customers without working powershell.

Considering the number of users who run this code, this means with this change we collectively save about 20 days in time worth of startup delay in VS Code, per month.

  1. We'd save 335-75 (260 ms) for customers by using the full path over the .exe shell resolved path when it works but we still have to try to resolve the path. However, we just use that by default now, which also saves time on the process spawn.

…processes

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI changed the title [WIP] Optimize Powershell scan execution time Optimize PowerShell availability check: file existence fast path before process spawning Mar 3, 2026
… test fails

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI changed the title Optimize PowerShell availability check: file existence fast path before process spawning Optimize PowerShell availability check: fast path with execution test and fallback to full validation Mar 3, 2026
…lDotnet when PS process launch fails

Co-authored-by: nagilson <23152278+nagilson@users.noreply.github.com>
Copilot AI changed the title Optimize PowerShell availability check: fast path with execution test and fallback to full validation Optimize PowerShell availability check: file existence fast path with automatic recovery Mar 3, 2026
nagilson and others added 2 commits April 8, 2026 16:09
- Remove redundant SYSTEMROOT env var check (Node.js on Windows
  provides case-insensitive env var access)
- Replace English-only stderr string matching with locale-independent
  error codes: ENOENT/EACCES/EPERM for OS-level failures, exit code
  9009 for cmd.exe 'not recognized' errors
- Skip retry when process was killed by signal (e.g. timeout)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nagilson nagilson self-requested a review April 8, 2026 23:59
nagilson added 2 commits April 9, 2026 12:08
…th check

im thinking the full path check will be more successful because it doesn't require proper shell resolution or path environment setup to work and most people will have a proper systemroot environment variable.
@nagilson nagilson marked this pull request as ready for review April 9, 2026 20:06
@nagilson nagilson requested a review from a team April 9, 2026 20:42
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.

2 participants