fix: speed up Windows process diagnostics#4228
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
ApprovabilityVerdict: 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. |
Summary
Root cause
The Windows diagnostics command queried
Win32_PerfFormattedData_PerfProc_Processonce for everyWin32_Processrow. 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-directivesvp run typecheckfromapps/servervp fmt ... --checkgit diff --checkRelated: #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_Processloop. The PowerShell script now loads allWin32_PerfFormattedData_PerfProc_Processrows 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; POSIXpsbehavior is unchanged.Tests pin the new command shape (single perf CIM call, no
-Filter), JSON parsing, scoped child cleanup on timeout, and boundedreadresults when the Windows query hangs. Several integration tests now setHostProcessPlatformexplicitly 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
readWindowsProcessRowsin ProcessDiagnostics.ts previously issued a separateGet-CimInstance Win32_PerfFormattedData_PerfProc_Process -Filter "IDProcess = ..."call for every process.Win32_PerfFormattedData_PerfProc_Process, materializes results into a hashtable keyed byIDProcess, then joins with a singleWin32_Processiteration usingContainsKey.Macroscope summarized d9673af.