Repository navigation
fix(bench): make bench:idle-cpu build, sample CPU and parse the process table on Windows - #27622
Conversation
Three independent Windows defects in the idle-CPU benchmark (its report is what Windows performance work would cite): - `buildAppIfNeeded` spawned `npx`, which is `npx.cmd` on Windows, so execFileSync failed with ENOENT before any sampling. Build through `config/scripts/run-electron-vite-build.mjs` instead — the repo's own Windows-safe wrapper, which also runs the boot-graph verification. - `readWindowsProcesses` returned `cpuTimeSeconds: null`, so the sampler's per-process CPU delta (idle-cpu-process-sampling.mjs:198) fell back to the hardcoded `percentCpu: 0` and every CPU KPI in the report was zero. Read `UserModeTime`/`KernelModeTime` from `Win32_Process` (100 ns units) and keep `null` when a host does not return them. Measured on Windows, same options before and after the CPU fix: | class | mean CPU before | mean CPU after | | --- | ---: | ---: | | renderer | 0 | 2.20 | | gpu | 0 | 2.08 | | utility | 0 | 0.11 | | agent-or-node | 0 | 0.06 | | total | 0 | 4.51 (p95 8.40) | RSS is unchanged (934 MiB -> 937 MiB), so only the CPU reporting changed. Refs #25235
… as zero Review follow-up (CodeRabbit). `Number(null)` is `0`, which is also a real counter value, so an absent `UserModeTime`/`KernelModeTime` passed the finite check and the sampler would report a kernel-only delta instead of taking the fallback. Require an actual number from the CIM payload. Verified on Windows that the real payload still reports CPU once the check is tight: total mean 4.40%, p95 14.48%, renderer 3.51%.
The mapping was only reachable through Get-CimInstance, so no test ran it. Lift it into cimCpuSeconds and assert the 100ns-to-seconds sum plus the missing / string / non-finite cases that must stay null.
…vives PowerShell writes to a redirected stdout in the OEM code page (437 here), which best-fits characters such as U+2022 and U+2192 in any running process's command line to raw 0x07 / 0x1A bytes. ConvertTo-Json had left them unescaped because they are not control characters in UTF-16, so the sampler's JSON.parse failed with "Bad control character in string literal" whenever such a process happened to be alive -- hence intermittent. Set [Console]::OutputEncoding to UTF-8, as the app's own CIM scan does, and cover it with a Windows-only test that fails without the fix. Fixes #25236
fetchRepos now requires a runtimeEnvironmentId, so the fixture's bare call threw "Cannot read properties of undefined (reading 'runtimeEnvironmentId')" before sampling on every platform. null selects this app's own catalog, as the e2e helpers already do.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The Windows benchmark build and sampling changes preserve their intended behavior, and the fixture now explicitly selects local repositories. No actionable merge risk remains in the reviewed changes. Pre-merge checks |
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
config/scripts/idle-cpu-process-sampling.mjs (1)
73-77: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueForce the JSON output to be an array and set an explicit depth.
The script pipes the process list directly to
ConvertTo-Json -Compress. The script runs under Windows PowerShell 5.1. With default settings, a single-item pipeline serializes as an object, not an array. The calling code handles this withArray.isArray(parsed) ? parsed : [parsed], so it works today.The change is optional. The same pattern was already present before this PR, and the learning concerns hardening only. To remove the dependence on the JS-side fallback, wrap the pipeline in
@(...)and pass-InputObjectwith-Depth.Source: Learnings
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Repository UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
00ba13d1-da04-460c-ae02-402f36b86a77
📒 Files selected for processing (3)
config/scripts/idle-cpu-process-sampling.mjsconfig/scripts/idle-cpu-process-sampling.test.mjsconfig/scripts/run-idle-cpu-benchmark.mjs
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.
The UTF-8 regression test self-skips off win32, so it must be registered in both Windows lists or it runs on no machine.
ELI5
The idle-CPU benchmark couldn't build on Windows, reported 0% CPU for every process, and sometimes crashed reading the process list. It now runs end to end and reports real numbers.
What Changed
npxthroughexecFileSync. On Windows that isnpx.cmd, so it failed withENOENT. It now runsconfig/scripts/run-electron-vite-build.mjswith the current Node, which also checks that the build's startup code loads cleanly.null, so every process reported 0%. It now readsUserModeTimeandKernelModeTimefromWin32_Process. A missing value staysnullinstead of turning into a believable 0.•or→in any running process's command line becomes a raw control byte, andJSON.parserejects it. That's why it was intermittent: it only failed while such a process happened to be running. The script now sets[Console]::OutputEncodingto UTF-8, the same line Orca's own process scan uses.fetchRepos()now needs its runtime argument, so the fixture threw before sampling on any OS. It now passes{ runtimeEnvironmentId: null }, as the end-to-end tests do.Why
Windows performance fixes need a working idle-CPU baseline.
The benchmark keeps its own PowerShell read instead of using
windows-process-table.ts. That module only runs inside Electron, and it deliberately exposes no CPU time or memory, which are the only things this benchmark measures.The first three commits are @paoValle's #25238, cherry-picked with authorship kept. They closed it only to cut down their open PRs. The UTF-8 and fixture fixes are new.
Linked Issue
Fixes #25236
Refs #25235: this fixes the idle-CPU part. The import crash is fixed in the companion PR.
Visual Proof
N/A: this is a command-line benchmark with no UI.
Testing
On Windows 11:
Before (main): the build step fails with
spawnSync npx ENOENT. With--skip-build, renderer, GPU and total CPU all show a mean of 0.After:
pnpm run bench:idle-cpu -- --warmup-ms 10000 --sample-ms 15000exits 0 with total mean CPU 4.86% (p95 9.74%), renderer 1.83% and GPU 2.67%. No Electron processes are left running.New Windows-only test: it starts a process whose command line contains
• → ♪and reads the process table. Without the UTF-8 fix it fails with the exact error from the issue ("Bad control character…"); with it, it passes. CIM time mapping is unit-tested.vitest5/5 passing;oxlint,oxfmtandcheck:code-quality:changedare clean.I manually tested these changes locally
Automated tests added/updated
Checklist
N/Awith reason