Skip to content

perf: keep CPU profiler active across bounded capture windows - #5112

Merged
ymichael merged 1 commit into
mainfrom
bb/perf-pr-keep-the-cpu-profiler-running-thr_jj8pzqt5hi
Oct 7, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/perf-pr-keep-the-cpu-profiler-running-thr_jj8pzqt5hi

Conversation

@ymichael

@ymichael ymichael commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

Performance diagnostics stopped and restarted V8's CPU profiler every 30 seconds. Restarting rebuilt its code map, causing recurring event-loop stalls in a large process. Stall detection logged the delay, but profiler operations were not instrumented, so the longest measured work could misleadingly name an unrelated heartbeat that took only 1 ms during a two-second stall.

What changed

Start the next named capture before ending the current one so V8 keeps its profiler active across bounded windows. Only two diagnostic captures briefly overlap; sampling, file limits, retention, and the final partial save remain. Initial activation and final teardown still run on the server thread.

Measure profiler start, completion, and serialization through the server's synchronous work tracker. Stall logs now explicitly report unattributed when the longest measured operation cannot explain the delay, allowing one sampling interval of tolerance. Otherwise they name a candidate, which still requires confirmation from profile stacks. The debugging guide documents the handoff and attribution fields. No server/daemon wire, SDK, or CLI contracts change.

How you verified

  • The continuous-window regression covers two rotations, unrelated named captures, and idempotent shutdown. Attribution regressions cover a two-second stall with only 1 ms of measured work and slow profiler start/completion/serialization through real capture and server wiring. The added attribution assertions fail before the fix and pass afterward.
  • pnpm exec turbo run test --filter=@bb/server -- test/system/event-loop-stall-monitor.test.ts test/system/performance-diagnostics.test.ts: 16 tests pass.
  • pnpm exec turbo run test --filter=@bb/process-utils -- test/performance-diagnostics.test.ts: 4 tests pass.
  • pnpm exec turbo run typecheck lint --filter=@bb/server --filter=@bb/process-utils, targeted server lint, and git diff --check pass.
  • Started pnpm start:worktree --perf-diagnostics and enabled the experiment in isolated dev data. Actual captures arrive every 30 seconds with approximately 0.08–0.13 ms handoff overlap. A 378 ms activation stall names cpu-profile:start; a separate 102 ms stall with only 7.2 ms of measured work reports unattributed. Verified the app and experiment toggle in a browser.
  • The integrated main/change benchmark measured median rotation overrun of 419.56 → 35.63 ms and maximum heartbeat delay of 417.04 → 37.53 ms. These are three rotations in a synthetic sized process on Node 22.23.1, not a reproduction of the production audit's 4.5-second maximum. Benchmark scripts and reports are retained outside the checkout.

AGENT GENERATED

@ymichael
ymichael merged commit 46067e7 into main Oct 7, 2026
48 checks passed
@ymichael
ymichael deleted the bb/perf-pr-keep-the-cpu-profiler-running-thr_jj8pzqt5hi branch October 7, 2026 18:43
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.

1 participant