Repository navigation
Fix: re-render loop guard counts a request once, not per ancestor - #5
jfversluis wants to merge 3 commits into
Conversation
The TASK-059 re-entrancy cap counted every ancestor component's wrapper a request climbed through, so a state change more than 50 components deep threw "Render loop detected" with no loop. The wrapper now hands the request up with RerenderReentrancy.BeginForward, and the parent wrapper it names recognises the hand-off and doesn't count it again. A real synchronous loop still stops after Max requests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
📦 Build metricsArtifact sizes for Packages (compressed .nupkg)
Assemblies in Microsoft.UI.Reactor
Assemblies in Microsoft.UI.Reactor.Advanced
Assemblies in Microsoft.UI.Reactor.Devtools
No size change beyond the noise floor. ✅ ✅ smaller / |
Review (gpt-6.1-sol) found the forward-mark fix still recursed through every ancestor callback, so a real loop deep in a tree could exhaust the stack before the cap fired, and a request marshalled to the UI thread counted without checking the cap. The component callback is now a small class; the innermost one walks its ancestors' callbacks, marking each self-triggered, and calls the host once. Counted once, constant stack, checked on the thread that does the work. The forward-mark API is removed. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Re-review (gpt-6.1-sol): a multicast parent callback (a handler mounting its child with before + ctx.RequestRerender) reports its last target, so the climb walked past it and dropped 'before'. Each link now keeps its canonical callback and the climb compares by reference; any other delegate is invoked as it is. Regression check in Lifecycle_RerenderDepthCap. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
/perf |
🧪 Merged coverageCoverage for
✅ higher / |
⚡ Reactor perf comparisonWorkload: Regression vs
|
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Renders/sec ↑ | 3.03 | 3.22 | +2.8% 95% CI [-2.9, +8.5] | ≈ within noise |
| Avg Reconcile (ms) ↓ | 119.2 | 115.9 | -1.1% 95% CI [-3.9, +1.8] | ≈ within noise |
| Avg Diff (ms) ↓ | 108.2 | 103.0 | -1.6% 95% CI [-4.2, +1.1] | ≈ within noise |
| Avg Memory (MB) ↓ | 288.6 | 291.7 | +0.9% 95% CI [+0.5, +1.3] |
Low-mutation skip-floor (--percent 0)
At --percent 0 the workload mutates few cells per tick (always at least one), so reconcile/diff isolate the O(n) per-tick child skip-walk floor that higher mutation rates dilute — ChildReconciler re-walks every child each tick even when nothing moved. The closer --percent is to 0, the more this floor is the signal, so a structural-skip optimization shows up cleanly where the headline table above buries it. Δ is the mean paired change with a 95% CI.
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Renders/sec ↑ | 14.60 | 14.71 | +0.7% 95% CI [-3.2, +4.5] | ≈ within noise |
| Avg Reconcile (ms) ↓ | 26.2 | 26.4 | +1.6% 95% CI [-4.0, +7.2] | ≈ within noise |
| Avg Diff (ms) ↓ | 24.4 | 24.8 | +2.4% 95% CI [-3.7, +8.5] | ≈ within noise |
| Avg Memory (MB) ↓ | 271.9 | 272.6 | +0.3% 95% CI [0.0, +0.7] | ≈ within noise |
Allocation (Reactor) — lower is better
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Alloc bytes/render ↓ | 4857088 | 4857629 | -0.2% 95% CI [-0.9, +0.5] | ≈ within noise |
| Gen0 GC / 1k renders ↓ | 156.25 | 144.96 | -4.0% 95% CI [-8.4, +0.4] | ≈ within noise |
Keyed-list workload (StressPerf.KeyedList, --percent 50)
A separate macro workload: a ~500-row stably keyed list whose rows are reordered / inserted / removed each tick. Because every child carries a key, the child reconciler takes its keyed arm (ReconcileKeyed → ReconcileKeyedMiddle, the LIS-based minimal-move pass) instead of the positional re-walk the StocksGrid tables above measure — so this is the sensitive macro signal for keyed-diff work the positional cells can never reach. Same interleaved paired-Δ 95% CI as the headline table.
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Renders/sec ↑ | 22.46 | 22.57 | +0.7% 95% CI [-0.4, +1.9] | ≈ within noise |
| Avg Reconcile (ms) ↓ | 12.0 | 12.1 | +1.1% 95% CI [-1.3, +3.4] | ≈ within noise |
| Avg Diff (ms) ↓ | 11.9 | 12.0 | +1.1% 95% CI [-1.3, +3.5] | ≈ within noise |
| Avg Memory (MB) ↓ | 179.5 | 180.2 | +0.1% 95% CI [-0.9, +1.2] | ≈ within noise |
Allocation (keyed-list) — lower is better
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Alloc bytes/render ↓ | 177668 | 177591 | -0.1% 95% CI [-0.3, +0.2] | ≈ within noise |
| Gen0 GC / 1k renders ↓ | 8.73 | 8.62 | -4.9% 95% CI [-14.2, +4.5] | ≈ within noise |
Flex/Yoga layout workload (StressPerf.Flex, --percent 50)
A separate macro workload: a deep nested, fully-realized (non-virtualized) flex tree (~2000 leaf cells) whose per-child flex inputs (grow / basis / width) are re-rolled on a --percent fraction of the leaves each tick, forcing a real Yoga measure/layout pass every frame while the unchanged leaves re-push identical inputs (the YogaNode setter-equality-guard / layout-cache-hit path). This drives the FlexPanel / Yoga LAYOUT engine — the sensitive macro signal for Yoga/Flex layout-engine allocation + memory work the positional StocksGrid and keyed-list legs can never reach. Same interleaved paired-Δ 95% CI as the headline table.
Reading this table: the reconcile / diff timing rows do not capture the deferred Yoga Measure/Arrange pass — it runs after the harness'
OnRenderCompletephase hook, inFlexPanel.MeasureOverride/ArrangeOverride. Judge layout-engine wins primarily on the flex allocation table below (process-wide GC counters capture the whole run, layout pass included) and the renders-per-second figure. The working-set memory figure is informational only — too coarse to resolve inline-per-node-array gains at this node count.
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Renders/sec ↑ | 1.65 | 1.62 | -1.7% 95% CI [-6.5, +3.1] | ≈ within noise |
| Avg Reconcile (ms) ↓ | 127.6 | 129.7 | +1.1% 95% CI [-0.7, +3.0] | ≈ within noise |
| Avg Diff (ms) ↓ | 124.4 | 126.9 | +1.5% 95% CI [-0.5, +3.5] | ≈ within noise |
| Avg Memory (MB) ↓ | 278.5 | 279.4 | -0.5% 95% CI [-2.3, +1.3] | ≈ within noise |
Allocation (flex) — lower is better
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Alloc bytes/render ↓ | 8603788 | 8604026 | +0.3% 95% CI [-0.4, +0.9] | ≈ within noise |
| Gen0 GC / 1k renders ↓ | 111.11 | 114.38 | +3.3% 95% CI [-22.1, +28.6] | ≈ within noise |
DataGrid control workload (StressPerf.DataGrid, --percent 50)
A separate macro workload: the real DataGrid control (DataGridComponent) over a 30-column × 200-row IObservableDataSource whose cells are mutated on a --percent fraction each tick, forcing a full DataGridComponent.Render() every frame. This re-runs — unconditionally, regardless of whether sort/filter changed — the per-render array/LINQ rebuilds (microsoft#663/microsoft#669) and re-allocates the per-realized-cell/row .OnTapped/.OnPointerPressed closures (microsoft#671) that the StocksGrid, keyed-list and flex legs never reach. Same interleaved paired-Δ 95% CI as the headline table.
Reading this table: the DataGrid's re-render is async / dispatcher-debounced (
DataChanged→LoadDataAsync→ coalescedforceRender+ a scroll-settle timer), so the reconcile / diff timing rows are noisier here and a render may be coalesced. Judge DataGrid allocation / delegate wins primarily on the DataGrid allocation table below (process-wide GC counters capture the whole run) and the renders-per-second figure. The working-set memory figure is informational only.
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Renders/sec ↑ | 5.77 | 5.71 | -1.1% 95% CI [-2.6, +0.5] | ≈ within noise |
| Avg Reconcile (ms) ↓ | 83.1 | 83.9 | +1.5% 95% CI [-0.7, +3.6] | ≈ within noise |
| Avg Diff (ms) ↓ | 83.0 | 83.8 | +1.4% 95% CI [-0.8, +3.5] | ≈ within noise |
| Avg Memory (MB) ↓ | 306.5 | 308.8 | +0.9% 95% CI [-0.6, +2.3] | ≈ within noise |
Allocation (datagrid) — lower is better
| Metric | main (baseline) |
This PR | Δ (95% CI) | Status |
|---|---|---|---|---|
| Alloc bytes/render ↓ | 12901392 | 12932771 | +0.2% 95% CI [-0.1, +0.4] | ≈ within noise |
| Gen0 GC / 1k renders ↓ | 135.59 | 136.76 | +5.0% 95% CI [-1.9, +11.9] | ≈ within noise |
Row memoization (opt-in) — same-build Baseline vs Memo
A separate single-build micro-bench (PerfBench.RowMemo, PR head only) that isolates the opt-in keyed row-memoization win from microsoft#327: a realistic 9-node variable-height row recycled 1,000,000 times through the real ElementFactory.BuildOrCache realize path — once without Memo (Baseline) and once with Memo(i, () => row) (Memo). The StocksGrid /perf legs can't show this (StocksGrid never opts into the API, so they read within-noise) and main lacks the Memo API entirely, so this leg is built + run from the PR head only, best-effort. Both arms share one build, so the two columns are an apples-to-apples A/B with no cross-tree drift; absolute ns is runner-dependent, so trust the Win ratios and the rebuilds→0 / CanSkipUpdate facts.
| Metric | Baseline | Memo | Win |
|---|---|---|---|
| ns/recycle ↓ | 801.0 | 68.3 | 11.7× faster |
| bytes/recycle ↓ | 4,360 | 176 | 24.8× less |
| factory rebuilds (per 1,000,000 recycles) ↓ | 1,000,000 | 0 | eliminated |
Why the real win is bigger than the table. On a recycle that re-asks a still-cached key,
Memoreturns the sameElementinstance, soReferenceEqualsholds andElement.CanSkipUpdateis true — the reconciler returns at the row root and skips the entire 9-node per-row descent and the downstream WinUI control-patch. That stacked reconcile + control-patch saving is not captured by the headless ns/bytes figures above (which time onlyBuildOrCache). Baseline hands the reconciler a fresh-but-equal tree every recycle (sameInstance=false,CanSkipUpdate=false), forcing the full walk.
Reconciler micro-benchmarks (PerfBench.ControlModel)
Production --variant Reactor control-model path, ns-resolution and WinUI-undiluted (spec-047 M1–M13) — ↓ lower is better. Status tracks allocated bytes/op, the authoritative signal here; it is deterministic for structurally-fixed benches, while dispatcher / background-thread benches carry a small process-to-process offset, so a bench is flagged only when its 95% CI clears a ±3% minimum-effect band (real structural alloc changes are several percent to many-x). ns/op is shown for context but is not auto-flagged (its paired CI is rep-interleaved but the flag remains dormant pending a real-CI identical-binary band calibration). Δ is the mean paired change with a 95% CI.
| Bench | main ns/op |
Δ ns (95% CI) | main B/op |
Δ alloc (95% CI) | Status |
|---|---|---|---|---|---|
IH1 ComboBoxEl100_SameItemsArray |
3820.8 | 0.0% 95% CI [-3.4, +3.3] | 1319.3 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
KX1 Keyed500_NoExit_Unchanged |
1151315.6 | +1.5% 95% CI [-1.0, +4.0] | 25538.6 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M1 Mount_Leaf_NoCallback |
92232.8 | +0.9% 95% CI [-1.5, +3.3] | 1140.9 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
IH2 ComboBoxEl100_EqualFreshItems |
19459.0 | +10.3% 95% CI [-4.8, +25.5] | 199.3 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
KX2 Keyed500_UnrelatedPanelExit_Unchanged |
1147105.0 | +1.2% 95% CI [-1.5, +4.0] | 25768.3 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M2 Mount_Leaf_OneCallback |
75010.4 | +1.1% 95% CI [-2.7, +5.0] | 3911.3 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
IH3 ComboBoxEl100_OneItemChanged |
13392.8 | +3.9% 95% CI [+1.2, +6.6] | 239.4 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
KX3 Keyed500_LocalExit_Unchanged |
1246395.1 | +1.3% 95% CI [-1.3, +3.9] | 25591.9 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M3 Mount_Leaf_ThreeCallbacks |
140833.2 | +1.0% 95% CI [-2.6, +4.6] | 8384.0 | -0.7% 95% CI [-1.5, +0.2] | ≈ within noise |
IH4 ComboBox100_EqualStrings |
2582.2 | +4.4% 95% CI [-3.6, +12.3] | 180.7 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
KX4 Keyed500_EmptyMemo_Unchanged |
1249911.9 | +1.5% 95% CI [-1.1, +4.1] | 25538.6 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M4 Dispatch_Switch_Cold |
79859.0 | -2.9% 95% CI [-9.6, +3.8] | 1903.1 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
IH5 ComboBox1000_EqualStrings |
12242.6 | +2.5% 95% CI [-1.8, +6.7] | 202.3 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M5 Dispatch_Switch_Warm |
76423.5 | -0.4% 95% CI [-5.3, +4.5] | 1902.0 | 0.0% 95% CI [-2.3, +2.4] | ≈ within noise |
IH6 ComboBox100_OneStringChanged |
17302.6 | +2.7% 95% CI [-1.8, +7.2] | 212.7 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M6 Dispatch_ExternalType |
62575.1 | -0.3% 95% CI [-1.6, +1.0] | 987.6 | +0.1% 95% CI [-3.0, +3.2] | ≈ within noise |
M7 Update_NoChange |
88808.4 | +0.7% 95% CI [-2.1, +3.4] | 452.1 | -0.8% 95% CI [-9.3, +7.6] | ≈ within noise |
M8 Update_OneLeafChanged |
27637.4 | -1.3% 95% CI [-4.8, +2.1] | 536.0 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M9 Update_AllChanged |
2470448.9 | +0.4% 95% CI [-1.7, +2.4] | 184278.1 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M10 EventHandlerState_Alloc |
53405.4 | +2.6% 95% CI [-1.3, +6.4] | 3740.1 | -0.2% 95% CI [-0.8, +0.4] | ≈ within noise |
M11 ModifierEHS_Frequency |
31741.2 | +1.2% 95% CI [-1.4, +3.8] | 945.2 | -0.1% 95% CI [-0.6, +0.4] | ≈ within noise |
M12 Pool_Rent_HotPath |
75997.3 | -0.8% 95% CI [-2.7, +1.1] | 1099.9 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M13 Setters_Suppression_Scope |
148.3 | +2.1% 95% CI [-7.0, +11.3] | 26.9 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
M14 Dsl_Rebuild_Cascade |
1396463.8 | +0.2% 95% CI [-0.9, +1.4] | 1999028.9 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
C207 ChangeHandler_DpRead_Coalesce |
1186.0 | +1.7% 95% CI [-6.9, +10.2] | 0.7 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
OAlloc Optional_Element_Alloc |
167.0 | +6.9% 95% CI [-1.8, +15.6] | 528.0 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
OUpdate Optional_Reconciler_Update |
10894.1 | +0.4% 95% CI [-3.1, +3.8] | 2852.8 | 0.0% 95% CI [0.0, 0.0] | ≈ within noise |
Cross-framework reference (same StocksGrid workload)
| Metric | vanilla WinUI3¹ | Rust windows-reactor² |
Reactor (this PR) |
|---|---|---|---|
| Renders/sec ↑ | 3.83 | 5.49 | 3.22 |
| Avg Reconcile (ms) ↓ | n/a | 20.2 | 115.9 |
| Avg Diff (ms) ↓ | n/a | 18.5 | 103.0 |
| Avg Memory (MB) ↓ | 263.2 | 198.0 | 291.7 |
↑ higher is better · ↓ lower is better. Within noise = the 95% confidence interval of the paired Δ includes 0 (no change resolvable at this sample size); ✅ improvement /
Allocation metrics (alloc bytes/render, Gen0 GC) are the sensitive signal for allocation-reduction work, where the mean-ms / memory figures are largely flat. They read n/a for a harness built from a revision that predates them (rebase the PR onto main to populate them).
Reconciler micro-benchmarks run PerfBench.ControlModel --variant Reactor (M1–M13) as a headless loop bracketed by per-thread alloc + GC counters — ns-resolution and free of WinUI render / working-set dilution, so they resolve Core/Reconciler allocation deltas the macro StocksGrid workload cannot. main and PR each link their own src/Reactor build and are rep-interleaved (a fresh alternated process per rep); Δ is the paired 95% CI over per-rep means. The Status column tracks allocated bytes/op (deterministic for identical code); ns/op is informational — its paired CI is now unbiased but the flag stays dormant pending a real-CI identical-binary band calibration.
¹ vanilla WinUI3 = StressPerf.Direct (imperative; no virtual-DOM, so it has no reconcile/diff phase — those cells read n/a). Measured live on this runner.
² Rust = test_reactor_perf from microsoft/windows-rs — a port of this harness (same StocksGrid, same --percent/--duration CLI). Built from source and measured live on this runner.
Absolute numbers are runner-dependent — trust the Δ vs main, not the absolute values. Memory (working set) is the noisiest metric.
Runner: CPU: INTEL(R) XEON(R) PLATINUM 8573C · 4 logical cores · 16 GB RAM · runner: GitHub Actions 1000015585.
Generated by .github/workflows/perf-compare.yml · PR 9e85a6e vs main 14172dc · 2026-11-24T20:50:00Z · run log.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
9e85a6e0e05f54d86a463c22b74d8c26176a2efa↑ Two cross-family reviews (gpt-6.1-sol): 2 high and 1 medium found and fixed; the final pass found nothing further.
↑
/perf(run 45474054133): all timing and allocation rows within noise.↓ One
/perfrun; working-set memory +0.9% on StocksGrid (not a gate metric).↓ The marshalled-request depth check has no dedicated test (a re-entrant dispatcher pump can't be built in a selftest).
Summary
The TASK-059 re-render loop guard counted every ancestor component's callback a request passed through, so a state change more than 50 components deep threw "Render loop detected" with no loop. The component callback is now a small class: the innermost one walks its ancestors' callbacks (marking each self-triggered, as before) and calls the host once. A request is counted once, climbs on a constant stack, and is checked on the thread that does the work. A real synchronous loop still stops after 50 requests.
Linked issue / spec
Phase 2b gate decision 5 (#4). Spec 067 §11.4. Stacked on #4. Report:
docs/reports/2026-11-24-phase-2c-protocol.md(#6).Test plan
Lifecycle_RerenderDepthCaprewritten: a real loop 201 deep stops after exactly 50 requests; a multicast parent callback runs in full; a change 201 deep renders after the loop threw.ci/depthfix-baseline, run 45473268469) failsLoopCountsRequestsNotWrappers(requests=0),DeepChainIsNoLoopandDeepChainRenders, in all three selftest tiers.9e85a6e0(run 45474045283): all green./perf(run 45474054133): within noise.Risk / breaking changes