Skip to content

fix: speed up Windows process diagnostics#4228

Open
StiensWout wants to merge 1 commit into
pingdotgg:mainfrom
StiensWout:fix/windows-process-diagnostics-timeout
Open

fix: speed up Windows process diagnostics#4228
StiensWout wants to merge 1 commit into
pingdotgg:mainfrom
StiensWout:fix/windows-process-diagnostics-timeout

Conversation

@StiensWout

@StiensWout StiensWout commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace the Windows per-process performance CIM lookup with one bulk performance query
  • join process and performance snapshots by PID in PowerShell
  • add deterministic coverage for command shape, parsing, timeout cleanup, and bounded error recovery

Root cause

The Windows diagnostics command queried Win32_PerfFormattedData_PerfProc_Process once for every Win32_Process row. That N+1 CIM pattern routinely exceeded the existing 1,000 ms diagnostics deadline.

The optimized command completed in all 25 local fresh-PowerShell samples (674–735 ms in the initial sample; 670 ms min, 701 ms median, 730 ms p95, and 733 ms max across the expanded 20-run sample). None exceeded 1,000 ms. This change intentionally keeps the existing deadline and limits scope to eliminating the expensive query pattern; a timeout increase can be considered separately if cross-machine evidence warrants it.

Impact

Windows process diagnostics now issue two CIM queries regardless of process count while preserving the existing output shape and zero CPU fallback when performance data is unavailable. POSIX behavior and all timeout values are unchanged.

Validation

  • vp test run apps/server/src/diagnostics/ProcessDiagnostics.test.ts (9 passed)
  • vp lint apps/server/src/diagnostics/ProcessDiagnostics.ts apps/server/src/diagnostics/ProcessDiagnostics.test.ts --report-unused-disable-directives
  • vp run typecheck from apps/server
  • targeted vp fmt ... --check
  • git diff --check

Related: #3610


Note

Low Risk
Scoped to Windows diagnostics PowerShell and test coverage; POSIX paths and timeouts are unchanged, with behavior preserved aside from performance.

Overview
Windows process diagnostics no longer run a per-process performance CIM lookup inside the Win32_Process loop. The PowerShell script now loads all Win32_PerfFormattedData_PerfProc_Process rows once into $perfByPid, then builds each process object with CPU from that map (still 0 when perf data is missing). Output shape and the 1s query deadline are unchanged; POSIX ps behavior is unchanged.

Tests pin the new command shape (single perf CIM call, no -Filter), JSON parsing, scoped child cleanup on timeout, and bounded read results when the Windows query hangs. Several integration tests now set HostProcessPlatform explicitly to linux.

Reviewed by Cursor Bugbot for commit d9673af. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Speed up Windows process diagnostics by replacing per-process CIM queries with a bulk query

  • readWindowsProcessRows in ProcessDiagnostics.ts previously issued a separate Get-CimInstance Win32_PerfFormattedData_PerfProc_Process -Filter "IDProcess = ..." call for every process.
  • Now performs a single bulk query of Win32_PerfFormattedData_PerfProc_Process, materializes results into a hashtable keyed by IDProcess, then joins with a single Win32_Process iteration using ContainsKey.
  • New tests cover the bulk query command structure, timeout/deadline behavior with scoped cleanup, and bounded results after a timeout.

Macroscope summarized d9673af.

@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a4930ba8-716b-47fa-a851-37b4078b34e3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Jul 21, 2026
@macroscopeapp

macroscopeapp Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Performance optimization that batches Windows CIM queries instead of running one per process. The change is small, behavior-preserving, and includes comprehensive test coverage for the new query pattern and timeout handling.

You can customize Macroscope's approvability policy. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant