Skip to content

perf(ci): wire reconciler micro-suite into /perf (ns + alloc, Core layer) - #693

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 6 commits into
mainfrom
azchohfi-perf-microsuite
Jun 26, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 6 commits into
mainfrom
azchohfi-perf-microsuite

Conversation

@azchohfi

Copy link
Copy Markdown
Collaborator

What & why

/perf measures only the StocksGrid macro workload, which is the wrong instrument for the Core/Reconciler layer most of the perf fleet optimizes. This PR (PR2 of the harness-improvement split; PR1 #691 added reps + paired-CI + a coarse process-wide alloc metric) wires in the existing PerfBench.ControlModel micro-suite (spec-047 M1–M13) so /perf also reports per-bench, ns-resolution, WinUI-undiluted main-vs-PR ns/op + B/op — the layer the fleet actually operates on, which /perf previously ignored.

Methodology rationale (local n=12 analysis)

The macro path could not resolve the deltas the fleet produces:

Problem (measured on 12 paired local reps) Evidence
2-run median is a coin flip A fresh 2-run median swings ±7–11% on timing; GH's headline renders/sec −0.6% reproduces its sign only 23% of the time (74% of 2v2 medians show PR faster).
The 4% floor preordains every sub-4% verdict The old blanket floor marks any |Δ|<4% "within noise" by construction, independent of run count — it both buries real sub-4% wins and rubber-stamps any sub-4% number.
renders/sec is reconcile-blind Reconcile is only ~24% of the StocksGrid frame cycle; ~76% is the WinUI measure/arrange/render thread. rps is a render-throughput metric, not a reconcile metric.
No allocation instrument Several fleet PRs reduce allocations; the macro path had no per-reconcile alloc signal (PR1's process-wide number is a coarse macro trend, diluted by WinUI/background allocs).
A real ~2–3.5% reconcile/diff signal was masked Local reconcile Δ is −3.56% (95% CI excludes 0); GH printed −1.2% but the floor hid it. The harness was hiding wins, not just failing to confirm them.

The micro-suite brackets only the reconcile body with per-thread alloc + GC counters (no render pipeline), so it resolves exactly what the macro path cannot.

What this adds

  • PerfBench.ControlModel builds self-contained per side — a scoped, opt-in PerfCiSelfContained MSBuild knob (unpackaged WindowsPackageType=None, so it builds on the runner without the packaged-app MakePri path). main and the PR each link their own src/Reactor, so the per-bench delta is a clean read on the code change.
  • A new micro section in the sticky comment: per-bench main vs PR ns/op + B/op with the same paired 95% CI machinery as the macro tables.
  • Run-PerfBenchmark.ps1 orchestration: -IncludeMicro (default on) / -MicroReps 12 / -MicroIterations 10000; best-effort build + run + compare after the Rust leg; threaded into the comment and result.json. Any micro failure leaves the macro comment untouched.

v1 flagging — alloc-driven, ns informational

I validated the leg end-to-end on this ARM64 box by running the same ControlModel binary as both "main" and "PR" (a true no-op diff). Result:

  • Allocated bytes/op is deterministic — 14/16 benches read exactly 0.0% Δ. Its paired CI is trustworthy, so the row Status tracks alloc.
  • ns/op is NOT deterministic across the two processes — with the per-side runs not yet rep-interleaved, a systematic process-to-process timing offset shifts every paired ns difference the same way and makes the paired CI exclude 0 even for an identical binary (one bench spuriously read −14.8% ns). So ns/op is shown for context but not auto-flagged in v1.

Sample comment section (rendered from the identical-binary validation run — note M3 reads −14.8% ns yet the row correctly stays "within noise" because alloc is unchanged):

Bench main ns/op Δ ns (95% CI) main B/op Δ alloc (95% CI) Status
M3 Mount_Leaf_ThreeCallbacks 142593.7 -14.8% 95% CI [-26.7, -2.9] 18066408 -2.1% 95% CI [-7.5, +3.4] ≈ within noise
M9 Update_AllChanged 1995411.0 -0.1% 95% CI [-1.2, +1.0] 368556160 0.0% 95% CI [0.0, 0.0] ≈ within noise

Rep-level interleaving of the two sides is the documented fast-follow that would promote ns to a flagged signal. (Per the coordinator's calibration: PR1's process-wide alloc = coarse macro trend; this micro-suite = the authoritative, WinUI-undiluted per-reconcile alloc instrument.)

Tests & docs

  • PerfLib.Tests.ps1: +46 micro assertions (162 total), including a no-false-flag property bench (clear ns improvement + unchanged alloc ⇒ row reads noise) and alloc-only row-status precedence.
  • RunPerfBenchmark.Tests.ps1: unchanged-green (21).
  • ci/README.md + METHODOLOGY.md: document the micro leg and the alloc-flagged / ns-informational v1 (with the empirical no-op finding and the interleaving fast-follow).

File-disjoint from src/Reactor and the perf fleet — touches only tests/perf_bench/PerfBench.ControlModel/* and tests/stress_perf/**. No /perf run is needed on this PR (it changes /perf itself); the fleet gets re-run after this lands.

Draft until reviewed.

…yer)

The /perf macro StocksGrid leg is render-bound and working-set diluted: rps
is ~76% gated by the WinUI render thread and the reconcile/diff/alloc figures
are measured across a live render pipeline, so it cannot resolve the small
Core/Reconciler deltas the perf fleet actually targets. The repo already ships
a purpose-built ns-resolution micro-suite (tests/perf_bench/PerfBench.ControlModel,
spec-047 M1-M13) that brackets only the reconcile body with per-thread alloc +
GC counters — and /perf ignored it. This wires it in.

What it adds:
- PerfBench.ControlModel builds self-contained per side (scoped, opt-in
  PerfCiSelfContained knob; unpackaged WindowsPackageType=None so it builds on
  the runner without the packaged-app MakePri path). main and PR each link their
  own src/Reactor, so the per-bench delta is a clean read on the code change.
- A new micro section in the sticky comment: per-bench `main` vs PR ns/op + B/op
  with the same paired 95% CI machinery as the macro tables.
- Run-PerfBenchmark.ps1 orchestration: -IncludeMicro/-MicroReps/-MicroIterations,
  best-effort build+run+compare after the Rust leg, threaded into the comment and
  result.json. Any micro failure leaves the macro comment untouched.

v1 flagging — alloc-driven, ns informational:
Local validation (running the SAME ControlModel binary as both "main" and "PR")
showed allocated bytes/op is deterministic (14/16 benches exactly 0.0% delta) but
ns/op is NOT: with the two per-side runs not yet rep-interleaved, a systematic
process-to-process timing offset shifts every paired ns difference the same way
and makes the paired CI exclude 0 even for an identical binary (one bench
spuriously read -14.8% ns). So the row Status tracks the deterministic alloc
signal; ns/op is shown for context but not auto-flagged. Rep-level interleaving
of the two sides is the documented fast-follow that would promote ns to a flag.

Why this matters (n=12 local analysis, see the PR2 description): the previous
/perf path was reconcile- and alloc-blind on the macro workload — rps is ~76%
render-bound, the old 4% floor preordained every sub-4% verdict as "noise", and
there was no allocation instrument for the layer most fleet PRs optimize. The
micro-suite is the authoritative per-reconcile allocation instrument; the macro
tables remain the user-facing throughput sanity check.

Tests: PerfLib.Tests.ps1 +46 micro assertions (162 total) incl. a no-false-flag
property bench (clear ns improvement + unchanged alloc -> row reads noise);
RunPerfBenchmark.Tests.ps1 unchanged-green (21). Docs: ci/README.md +
METHODOLOGY.md document the micro leg and the alloc-flagged/ns-informational v1.
File-disjoint from src/Reactor and the perf fleet.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Wires the existing PerfBench.ControlModel reconciler micro-benchmark suite into the /perf CI harness so perf-compare reports WinUI-undiluted Core/Reconciler deltas (ns/op + B/op) alongside the existing StocksGrid macro workload.

Changes:

  • Adds an opt-in micro-benchmark leg to Run-PerfBenchmark.ps1 that builds/runs PerfBench.ControlModel per side and threads results into comment.md and result.json.
  • Extends PerfLib.ps1 with JSONL parsing, paired-CI comparison, and markdown rendering for the micro-suite section.
  • Documents the methodology/interpretation (alloc drives status; ns informational until rep-level interleaving) in ci/README.md and METHODOLOGY.md, and adds unit coverage in PerfLib.Tests.ps1.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/stress_perf/METHODOLOGY.md Documents why/when micro-benches are needed and how to interpret ns vs alloc in v1.
tests/stress_perf/ci/Run-PerfBenchmark.ps1 Orchestrates best-effort build/run/compare of the micro-suite and threads it into outputs.
tests/stress_perf/ci/README.md Adds user-facing harness docs for the micro-benchmark leg and new flags.
tests/stress_perf/ci/PerfLib.Tests.ps1 Adds unit tests for parsing/comparison/rendering and “no false flag” status behavior.
tests/stress_perf/ci/PerfLib.ps1 Adds micro-suite parsing/comparison and integrates micro section into the sticky comment.
tests/perf_bench/PerfBench.ControlModel/PerfBench.ControlModel.csproj Adds PerfCiSelfContained knob to allow self-contained CI builds on the runner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/stress_perf/ci/PerfLib.ps1 Resolved
…t discard

Two correctness fixes from the PR #693 Copilot review:

1. Read-MicroBenchResults now tags each sample with its repetition index, and
   Get-PerfMicroComparison pairs the two sides BY REPETITION rather than by array
   position. Previously a dropped/errored repetition on one side (its row filtered
   out) compacted the arrays, so every later sample shifted left and the paired CI
   compared main rep i against pr rep i+1 — silently mis-pairing. This mirrors the
   macro path's null-placeholder defense. New regression test: main has reps 0..3
   (rep1 an outlier), pr is missing rep1 → the paired alloc Δ resolves to the clean
   -10% over the common reps {0,2,3} instead of being smeared by the mismatch.

2. Invoke-MicroRun now discards any output on timeout and returns $null. The bench
   writes results.jsonl incrementally (one line per rep, flushed between benches),
   so a killed run leaves a truncated prefix subset; accepting it would compare a
   silent subset of benches/reps. A timeout now omits the micro section instead.

Tests: PerfLib.Tests.ps1 168 assertions (was 162); RunPerfBenchmark.Tests.ps1 21.
Real-data happy path unchanged (full rep intersection → identical result).

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment thread tests/stress_perf/ci/PerfLib.ps1 Resolved
… medians

Two follow-up fixes from the PR #693 re-review:

1. Invoke-MicroRun now also discards output when the harness exits non-zero (not
   only on timeout). A clean run exits 0 — per-bench exceptions are caught and
   written as a filtered status:"error" row, so they don't fail the process — so a
   non-zero exit means a crash, and because results.jsonl is written incrementally
   that leaves a truncated prefix. Discard it rather than compare a silent subset.

2. Get-PerfMicroComparison now computes the DISPLAYED medians (MainMeanNs / PrMeanNs
   / MainAllocBytes / PrAllocBytes) over the SAME rep-aligned sample set used for the
   paired CI, instead of over all per-side samples. Previously, when a repetition was
   missing on one side, the table's main/PR columns and its Δ could be drawn from
   different reps. New test bench A2: main's unpaired rep sits at the ns median
   position, so the displayed median must be 20 (aligned {0,2,3}) not 25 (all four).

Tests: PerfLib.Tests.ps1 172 assertions (was 168); RunPerfBenchmark.Tests.ps1 21.
Real-data happy path unchanged (full rep intersection -> identical medians/Δ).

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

…n-effect band

Addresses the pr-review skill findings + a gate-5 smoke finding on real
PerfBench.ControlModel data (16 benches x 6 reps, identical binary A/B):

F2 (must-fix): Get-PerfMicroComparison flagged better/worse off the point-delta
fallback when < 2 rep-aligned pairs survive (Get-PerfPairedDeltaStats returns
$null). Add -RequirePairedCI to Get-PerfDelta: with no admissible paired CI the
micro path now returns 'na' (N=$null) instead of a one-sample flag. Macro path
keeps the legacy fallback (switch defaults off).

F1: alloc was displayed as B/op but allocBytes is the per-rep loop TOTAL while
meanNs is per-op. Read-MicroBenchResults now divides allocBytes by the row's
iterations so the B/op column and per-op ns share one basis (M1: 4,474,872 /
4000 = 1118.7 B/op). Constant divisor preserves determinism.

Minimum-effect band (gate-5 smoke): not every micro bench is alloc-deterministic
— dispatcher / background-thread benches (M5 "Dispatch_Switch_Warm" measured 6/6
distinct alloc values per rep) carry a sub-1% systematic process-to-process
offset that the within-process CI can't cancel, so the tight CI excluded 0 and
false-flagged 'worse' at +0.3% on identical code. Add -MinEffectPct to
Get-PerfDelta: the micro ALLOC delta now flags only when the 95% CI clears a
+-1% band (real structural alloc changes are several percent to many-x; RECON's
~3KB/cell fix is far above it). This is a CI-vs-band test on the non-interleaved
micro alloc metric, NOT the blanket point-delta floor PR1 removed. ns stays
informational-only (pure CI-excludes-0). Band documented in the rendered
section preamble.

F4: add .PARAMETER help for IncludeMicro / MicroReps / MicroIterations.
F5: cover Invoke-MicroRun discard paths (timeout, non-zero exit, empty output).
F6: lock 0/1-common-rep -> 'na' behavior.

Tests: PerfLib.Tests.ps1 188 assertions, RunPerfBenchmark.Tests.ps1 25
assertions, both green. Smoke on real jsonl: all 16 benches read noise/na (no
false flag), per-op alloc cross-checked against raw median/iterations.
Measurement-tooling only; zero src/Reactor changes.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Copilot review on 67d0e57: the Start-Process / Start-Sleep stubs were removed
only on the straight-line path, so a throwing assertion would skip cleanup and
leak the stubs into the rest of the script. Move the removals into a finally so
teardown is deterministic regardless of assertion outcome. No assertion change
(still 25 green).

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread tests/stress_perf/ci/PerfLib.ps1 Resolved
Copilot review on 7ed6ba9: Read-MicroBenchResults required benchId/meanNs/
allocBytes but not repetition, yet it sorts by and casts [int]\.repetition. A
row missing repetition (schema drift / truncation) or with a non-numeric value
would throw PAST the malformed-line guard and break /perf comment generation,
contradicting the 'malformed lines are skipped' contract. Require the property
and validate the [int] cast at ingestion; skip the row if it won't parse. Adds 4
assertions (missing + non-numeric repetition both dropped, surviving reps are the
valid ones, no throw). 192 green; real-data smoke still parses 16 benches.

Co-authored-by: Copilot <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

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.

2 participants