perf(retained): pair native-memory rows and observe the viewer's workers (Refs #7955)

Merged
LO
1mo ago
+434-20

Refs #7955 (item 6 qualification). Measurement code only; no thresholds, no plan rules changed.

A non-exclusive pre-flight of the retained qualification runners at the plan's fixture size (advanced_model, Holter) found two gaps in the runners themselves:

  • Native memory rows could never pair. retained-qual-native-memory.mjs measures one process per sample, so a paired cohort is many invocations, and retained-qual-report.mjs keyed rounds by each invocation's startedAt. Every base/branch native comparison came out unpaired. The runner now takes --round N --pairing-id ID (both or neither); pairingId travels in row provenance, and the reporter pairs by it when present.

  • PLAN.md asks for a viewer worker count; only navigator.hardwareConcurrency was recorded. The viewer init script now wraps the page's Worker constructor and records pageWorkersCreated, pageWorkersPeakLive (counted via terminate()) and pageWorkersByScript. Workers started inside a worker (the SDK's private one) are not visible, and the row says so.

  • The viewer's --timeout-ms could not fire on a saturated page (second commit, b26de88ea0). Playwright polls the waitForFunction predicate inside the page. In the Holter pre-flight the renderer's main thread stayed busy past 70 min and the 60-min timeout never triggered, which would hang a whole cohort. The wait is now also bounded from Node (raceWithTimeout, as browser-memory already does), so a stuck page becomes a failed row and the browser is closed. A regression test covers it.

Verification:

  • node --test scripts/perf/*.test.mjs: 304 pass, 0 fail (head 79ee0adcf9); retained-qual-* 87/87 at b26de88ea0. New tests cover pairing-id pairing (and its absence), --round/--pairing-id validation, and worker counting in the page script.
  • Real viewer on Pop (headed Chrome on a private Xvfb, hardware nvidia/lovelace adapter, retained engine, advanced_model, one non-exclusive round): sample OK; 4 page workers (parser, retained, source-identity, source-compression), peak 3 live.
  • node scripts/pre-handoff.mjs --base origin/main: all gates pass. "retained-free viewer" was SKIPPED because there was no default viewer build in the checkout; CI runs it.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Performance reports include page-created worker counts, peak live workers, and per-script totals.
    • Native memory samples can be paired across separate runs using a shared pairing ID and round number.
  • Bug Fixes
    • Performance comparisons group samples more consistently, and viewer sampling enforces its timeout when a page is unresponsive.
  • Documentation
    • Clarified worker measurement limits and native memory pairing requirements, including the need for an identified host.