Skip to content

Don't let a reused or memoized panel child swallow a component's own update - #1308

Merged
Alexandre Zollinger Chohfi (azchohfi) merged 4 commits into
mainfrom
azchohfi-memoized-child-skips-self-rerender
Oct 1, 2026
Merged

Alexandre Zollinger Chohfi (azchohfi) merged 4 commits into
mainfrom
azchohfi-memoized-child-skips-self-rerender

Conversation

@azchohfi

@azchohfi Alexandre Zollinger Chohfi (azchohfi) commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A component that sets its own state never re-rendered when the element holding it was the same instance on every render: a reused element (an app that re-emits one DockManager), an explicitly memoized wrapper such as UseMemo(() => Border(Counter()), []), a reused children array, or a Memo(key, …) used as a plain panel child. The child-skip arms in ChildReconciler (positional UpdateCommonChild, keyed prefix, keyed suffix) skip any CanSkipUpdate-equal child without consulting the dirty-ancestor path, so the root-down pass stopped above the component. Its node stayed self-triggered and the new state never rendered; a reused DockManager never drained a queued model.PinToSide or Float. UpdateCommonChild documented this as a residual edge. It reproduces in every shape.

The fix:

  • Skip arms decline only for dirty children. PopulateDirtyAncestorPath now also records, for each control on the path, which child the path continues through. ChildReconciler.Reconcile resolves a container's dirty children once (Reconciler.ResolveDirtyChildIndices), using one IndexOf per dirty child. The three skip arms then decline exactly those indices: an integer compare for one dirty child, a binary search for several. A declined child goes through Update, whose existing IsOnDirtyAncestorPath gate continues the descent.
  • The hot skip floor is unchanged. When nothing in the pass self-triggered, resolution costs one field check and no child's control is read. When a component elsewhere self-triggered, a container off the path pays one hash lookup. No case reads a control per skipped child. The per-child probe is only a fallback for a parent that isn't the collection's owner, such as a third-party Panel<> descriptor whose GetCollection returns an inner panel. Every in-repo Panel<> uses c => c.Children.
  • The PR-C structural fast-path gate uses the resolved indices. Its comment called that gate "behaviorally redundant". It is now load-bearing, because the full walk declines for dirty cells and the fast path would skip them wholesale.
  • Memo(key, …) as a plain child. The same-key arm in Reconciler.Update returned null without descending. When the control is on the dirty path, it now re-runs the factory, which is pure by contract, and reconciles that output against itself, so only the dirty path descends. Same-key passes that don't involve the subtree remain no-ops, with no factory call; a fixture pins this. The XML docs and the collections guide are updated.
  • Docs. The residual-edge comment in UpdateCommonChild and the fast-path gate comment are rewritten. The reconciliation guide is updated (template plus compiled page, since the child-diff snippet changed). There is a CHANGELOG entry under Fixed.

Linked issue / spec

No issue was filed: this PR is the report. It extends the dirty-ancestor path added in #377. Existing comments call it "#681's dirty-ancestor path", but #681 is an unrelated Yoga issue, so the new comments don't repeat that label.

Test plan

The regression fixtures are in tests/Reactor.AppTests.Host/SelfTest/Fixtures/SelfTriggeredReusedChildFixtures.cs. They are selftests because the path needs live component wrappers and the visual-tree walk that builds the dirty path, and headless code can't construct either. In each fixture the component's own button changes state, so only the self-triggered path can deliver the update:

  • Positional: a reused instance, with an in-fixture positive control (a sibling counter rebuilt every render, which updates on main too). Also a memoized Border(Counter()), a nested reused tree, and a UseMemoCellsByIndex hinted range.
  • Keyed prefix and keyed suffix.
  • A reused DockManager as a panel child, where model.PinToSide and model.Hide must drain.
  • A Memo(key, …) panel child. An unrelated pass must not re-run the factory or re-render the component.
  • A negative case: a reused sibling that is not on the dirty path stays skipped.
  • DirtyChildrenFoundByIndex captures ResolveDirtyChildIndices mid-pass. It returns At(1) for one dirty child and AtAll(1,3) for two in the same pass, which proves the IndexOf path runs rather than the per-child probe.
  • InnerPanelCollectionUsesFallback registers a descriptor whose Panel<> collection is an inner StackPanel, so the dirty child can't be found by index. A reused counter must still update, and the mid-pass capture asserts ProbeEachChild.
  • Headless tests in tests/Reactor.Tests/DirtyChildIndicesTests.cs: the index modes never read a control, and AtAll sorts its input for the binary search. With nothing self-triggered, neither resolution nor the positional and keyed skip floor reads a control or calls IndexOf.

Results, with exact commands:

  • Baseline: git stash of src and docs, so origin/main 885a5d8d0 product code with the new fixtures. Reactor.AppTests.Host.exe --self-test --filter "SelfTrigReuse" → 36 failures across 9 fixtures (the two capture fixtures need the new API). The positive control passed. The DockManager fixture reported pending=1, then pending=2.
  • Fix: the same command on the merge head 2da96c364 → 11 fixtures, 0 failures.
  • Revert proofs by in-place mutation. For each, the edit was confirmed in git diff, the Reactor.dll rebuild was confirmed by timestamp, and the tree was restored until git status --porcelain was empty. The first four ran before the fallback fixture existed.
    • Both halves off → 40 failures, all 10 fixtures red.
    • Only the ChildReconciler half off → 34 failures; Memo(key, …) stays green.
    • Only the Memo(key, …) half off → exactly its 6 checks fail.
    • Dropping the second dirty child of a shared parent → exactly the two two-sibling checks fail (resolved=At(1), rendersB=1).
    • Probe fallback always answering "not dirty" → exactly InnerPanelCollectionUsesFallback fails (5 checks, renders=1); everything else stays green.
  • dotnet test tests/Reactor.Tests --no-build -p:Platform=x64 → Passed: 14,401 total, 0 failed, 64 skipped.
  • dotnet test tests/Reactor.SelfTests --no-build -p:Platform=x64 → 1,711 total: 1,709 passed and 1 skipped (the deliberate SelfTestVerdict_OnlySkips_PositiveControl). The 1 failure, WindowLevel_RuntimeFlip_Topmost, is open flake [Flaky] WindowLevel_RuntimeFlip_Topmost fails intermittently in the full selftest run #927: a race on the native WS_EX_TOPMOST style bit that fails in about a third of full runs on clean main and passes in isolation. It was also the only failure before the merge, and it passed in isolation on both builds.
  • dotnet restore Reactor.slnx, then dotnet build Reactor.slnx --no-restore -c Release -p:CI=true → succeeded with 0 errors. The only warnings are 2 WIN2D0001 MSBuild warnings from AnyCPU Win2D projects this PR doesn't touch.
  • mur docs compile --topic collections and --topic reconciliation → only the edited paragraphs and the changed child-diff snippet moved.
  • Merge check: Tag controls mounted through Reconciler.RegisterType #1301 and Bind devtools HTTP listeners without a probe-then-bind race #1309 have since landed on main. Merging them in (2da96c364) conflicted only in CHANGELOG.md, where both sides added an entry at the same spot under Fixed; both entries are kept. Tag controls mounted through Reconciler.RegisterType #1301's Reconciler.cs changes (registered-type tagging, the unmount guard, .Ref clearing) merged automatically and don't touch the dirty path, the child-skip arms or Memo(key, …). The merge leaves the PR's code, docs and test diff against main unchanged (same git patch-id --stable). On the merged tree, the SelfTrigReuse (11), RegisterType (15), NativeDocking (83), StructuralSkip (3) and Issue811 (7) fixture sets all pass. git merge-tree --write-tree with the still-open Keep an AutoSuggestBox alive until its deferred TextChanged has fired #1302 (9e31a1292) and Close a docking host's floating windows whichever DockManager opened them #1305 (803aaff55) is clean. Close a docking host's floating windows whichever DockManager opened them #1305 re-keys DockHostModelBridge by host identity but keeps Get(DockManager), so the DockManager fixture stays valid after it lands.

The unit, selftest and Release-build results above are from the merge head 2da96c364. They were first run on 00ebf52f8, with the same single selftest failure.

CI: on 5c9dc87a8, the last head before the merge, every check passed (44 passed, 2 skipped by design). On the merge head 2da96c364, attempt 1 had 42 passes and two failures, both already-tracked flakes:

Neither fixture can reach this PR's code. Both mount a root render function with ctx.UseState, and the chart isn't .Interactive(), so there is no component node to self-trigger. The new code then stops at its first field check, and the Memo(key, …) arm never matches. The identical code diff passed both shards on 5c9dc87a8, and both fixtures passed in my local full run of the merged tree. After that analysis I re-ran the two failed jobs once, and both passed: the head is now 44 passed and 2 skipped. Earlier, on f6875a148, the only failure was AOT Asym_Removed, open flake #1037.

Perf

Local run of Run-PerfBenchmark.ps1 -BaselineRoot <main worktree> -Percent 50 -Duration 10 -Reps 4 -Warmup 1: main and this branch interleaved on one i9-14900K, x64 Release. The machine is shared, so it is noisy, and absolute renders/sec are low here (vanilla WinUI3 managed only 4.81); trust the deltas. Every metric is within noise: every 95% CI includes 0.

Leg Metric main PR Δ (95% CI)
StocksGrid 50% Renders/sec ↑ 4.99 5.10 +4.2% [-7.2, +15.7]
Avg Reconcile (ms) ↓ 32.9 31.8 -4.4% [-19.1, +10.2]
Avg Diff (ms) ↓ 28.9 28.3 -4.1% [-18.5, +10.3]
Avg Memory (MB) ↓ 279.4 277.2 -0.5% [-1.3, +0.3]
Alloc bytes/render ↓ 4,927,500 4,817,831 -1.7% [-4.3, +1.0]
Skip floor (--percent 0) Renders/sec ↑ 14.27 14.29 -0.3% [-2.4, +1.8]
Avg Reconcile (ms) ↓ 10.1 10.3 +3.6% [-8.9, +16.1]
Avg Diff (ms) ↓ 9.2 9.5 +3.8% [-8.5, +16.2]
Keyed list Renders/sec ↑ 14.62 14.87 +1.8% [-1.6, +5.2]
Avg Reconcile (ms) ↓ 6.0 6.2 +7.4% [-18.1, +32.9]
Alloc bytes/render ↓ 172,753 172,652 -0.1% [-0.2, 0.0]
PerfBench.ControlModel B/op 0.0% on 15/17 benches, all within noise

CI /perf (sticky comment; run 36908028150): 12 paired runs per side after 2 warmups, windows-latest x64, head 93628b4fd. That is the last product change before the binary search, which only affects passes with two or more dirty siblings in one panel, and no perf leg has those. No regression on any leg.

Leg Metric main PR Δ (95% CI) Status
StocksGrid 50% Renders/sec ↑ 2.79 2.85 -0.1% [-4.0, +3.8] ≈ noise
Avg Reconcile (ms) ↓ 123.5 123.1 -1.3% [-6.3, +3.7] ≈ noise
Avg Diff (ms) ↓ 111.6 111.2 -0.9% [-5.4, +3.6] ≈ noise
Avg Memory (MB) ↓ 284.9 284.8 -0.2% [-0.7, +0.4] ≈ noise
Alloc bytes/render ↓ 5,004,768 4,972,837 -1.0% [-2.2, +0.2] ≈ noise
Skip floor (--percent 0) Renders/sec ↑ 16.22 15.87 +0.2% [-5.6, +5.9] ≈ noise
Avg Reconcile (ms) ↓ 36.6 37.2 +1.9% [-3.0, +6.8] ≈ noise
Avg Diff (ms) ↓ 34.1 35.1 +2.1% [-3.1, +7.3] ≈ noise
Keyed list Renders/sec ↑ 20.71 21.34 +3.3% [+0.8, +5.9] ✅ flagged
Avg Reconcile (ms) ↓ 15.7 15.2 -2.1% [-4.4, +0.2] ≈ noise
Alloc bytes/render ↓ 172,914 172,340 -0.4% [-0.7, -0.1] ✅ flagged
Flex/Yoga Renders/sec ↑ 1.24 1.24 +0.5% [-4.2, +5.2] ≈ noise
DataGrid Renders/sec ↑ 4.67 4.74 +1.1% [-2.2, +4.3] ≈ noise
Avg Reconcile (ms) ↓ 105.4 103.6 -0.9% [-4.3, +2.5] ≈ noise
Alloc bytes/render ↓ 13,812,260 13,775,729 -0.2% [-0.7, +0.2] ≈ noise
PerfBench.ControlModel (17 benches) B/op exactly 0.0% on 12; all rows ≈ noise ≈ noise

How to read these:

  • The skip-floor leg isolates the per-tick child skip walk this PR touches. The StocksGrid root is not a component node, so those passes have no dirty path and the new code is a single field check per panel.
  • The DataGrid leg is the one that exercises the new dirty-pass code. DataGridComponent re-renders itself through UseReducer, so every pass has a populated dirty path and resolves dirty indices on the DataGrid's ancestor panels. It is within noise.
  • I don't attribute the flagged keyed-list gains to this change: nothing in it speeds up the keyed arm. Treat them as noise.
  • The one micro-bench row with a CI above 0 is M7 Update_NoChange B/op +9.2% [+2.0, +16.5]; it stays under the ±3% flag band. Its timed loop runs no changed code: UpdateChild(e, e, control) on reference-equal leaves returns at Update's untouched element-level skip. Its 370 B/op is mostly the amortized one-time mount of 1000 TextBlocks, and it read +5.5% [-12.1, +23.2] in the local run.

Risk / breaking changes

  • No public API change. IChildCollection is internal; its new IndexOf has a default implementation, and every other new member is internal.
  • Behavior. A component inside a reused or memoized child now re-renders on its own state change; before, that update was silently dropped. A same-key Memo(key, …) re-runs its factory only on passes where a component inside it updated itself. That is safe under the factory's purity contract: the output is reconciled against itself, so nothing off the dirty path is written. Passes that don't involve the subtree still don't call the factory.
  • Perf-sensitive path: the child skip floor. When nothing self-triggered, each container reconcile pays one field check. When something did, each container on the path pays one IndexOf per dirty child.
  • Pre-existing and unchanged: a positional type-mismatch replacement under an exit transition re-inserts the outgoing control mid-loop, which shifts the indices of later children. That already affects children.Get(i) for every later child; the dirty indices share the same assumption.

…update

A component that updates its own state is reached by a pass that starts at the
root. The child-skip arms in ChildReconciler (positional UpdateCommonChild and
the keyed prefix/suffix loops) skipped any child for which
Element.CanSkipUpdate held, and a reference-equal child always does: a reused
element instance (an app re-emitting one DockManager), an explicitly memoized
wrapper such as UseMemo(() => Border(Counter()), []), or a reused children
array. Those arms never consulted the dirty-ancestor path, so the descent
stopped at the reused child and the component's new state never rendered.
Memo(key, ...) used as a plain panel child had the same hole one layer down:
its same-key update arm returned without descending.

The skip arms now decline for exactly the children that lead to a
self-triggered component. The dirty-ancestor walk also records which child
each path control descends through, and ChildReconciler resolves a panel's
dirty children once per reconcile with one IndexOf each, so the skip floor
stays free of a per-child COM read: membership is an integer compare, and
with nothing self-triggered in the pass the resolution is a single field
check. A same-key Memo(key, ...) on the dirty path re-runs its (pure) factory
and walks the output against itself to reach the component.

Selftest fixtures cover the positional path (reused instance, memoized wrapper,
nested reused tree, hinted range), the keyed prefix and suffix arms, a reused
DockManager whose model queue never drained, Memo(key, ...), a reused sibling
that must stay skipped, and the index resolution itself; headless tests pin
that the no-dirty-path skip floor reads no control.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@azchohfi

Copy link
Copy Markdown
Collaborator Author

/perf

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build metrics

Artifact sizes for 2da96c3 vs the base branch (cdb5d14).

Packages (compressed .nupkg)

Artifact base PR Δ
Microsoft.UI.Reactor.nupkg 1.75 MB 1.75 MB +2.83 KB (+0.16%) ⚠️
Microsoft.UI.Reactor.Advanced.nupkg 491.8 KB 491.8 KB +14 B (0.00%) ≈
Microsoft.UI.Reactor.Devtools.nupkg 287.9 KB 287.9 KB +14 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor

Artifact base PR Δ
Reactor.Analyzers.dll 373.0 KB 373.0 KB +0 B (0.00%) ≈
Reactor.dll 2.48 MB 2.48 MB +2.00 KB (+0.08%) ⚠️
Reactor.Localization.Generator.dll 16.0 KB 16.0 KB +0 B (0.00%) ≈
Reactor.Wrappers.Abstractions.dll 10.5 KB 10.5 KB +0 B (0.00%) ≈
Reactor.Wrappers.Generator.dll 99.5 KB 99.5 KB +0 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor.Advanced

Artifact base PR Δ
Reactor.Advanced.dll 1023.5 KB 1023.5 KB +0 B (0.00%) ≈

Assemblies in Microsoft.UI.Reactor.Devtools

Artifact base PR Δ
Microsoft.UI.Reactor.Devtools.dll 788.5 KB 788.5 KB +0 B (0.00%) ≈

✅ smaller / ⚠️ larger / ≈ within noise. Sizes come from a Release dotnet pack on the CI runner: packages are the compressed .nupkg download size, assemblies the uncompressed DLL inside it.
workflow run.

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.

Copilot review overview

🟡 Changes recommended

The third-party panel fallback lacks a positive live regression test and could regress undetected.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Fixes swallowed self-triggered updates beneath reused or memoized panel children.

Changes:

  • Tracks dirty child indices through reconciliation skip paths.
  • Allows same-key Memo subtrees to descend for internal state updates.
  • Adds regression tests and updates documentation.
File Description
src/​Reactor/​Core/​Reconciler.cs Tracks dirty-path child relationships.
src/​Reactor/​Core/​ChildReconciler.cs Declines skips for dirty children.
src/​Reactor/​Core/​ChildCollection.cs Adds child index lookup.
src/​Reactor/​Core/​Reconciler.Update.cs Descends into dirty keyed-memo subtrees.
src/​Reactor/​Core/​Reconciler.Mount.cs Updates keyed-memo documentation.
src/​Reactor/​Core/​Element.cs Documents keyed-memo behavior.
src/​Reactor/​Elements/​Dsl.cs Updates Memo API documentation.
tests/​Reactor.Tests/​DirtyChildIndicesTests.cs Tests index modes and skip costs.
tests/​Reactor.AppTests.Host/​SelfTest/​Fixtures/​SelfTriggeredReusedChildFixtures.cs Adds live regression scenarios.
tests/​Reactor.AppTests.Host/​SelfTest/​SelfTestFixtureRegistry.cs Registers new fixtures.
docs/​_pipeline/​templates/​reconciliation.md.dt Updates reconciliation source documentation.
docs/​_pipeline/​templates/​collections.md.dt Documents keyed-memo exception.
docs/​guide/​reconciliation.md Regenerates reconciliation guide.
docs/​guide/​collections.md Regenerates collections guide.
CHANGELOG.md Records the behavior fix.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🧪 Merged coverage

Coverage for 2da96c3 vs the base branch (19f6c50) — unit + selftest merged.

Metric base PR Δ
Line 86.17% 86.15% -0.02 pp ≈
Branch 77.40% (966/1248) 77.40% (966/1248) 0.00 pp ≈

No coverage change beyond the noise floor. ✅

✅ higher / ⚠️ lower / ≈ within noise. Δ is in percentage points; coverage is unit + selftest merged (Debug x64) on the CI runner. Cobertura reports attached to the workflow run as artifacts.

A descriptor whose Panel<> collection belongs to an inner panel hands the child reconciler a parent that does not own the collection, so the dirty child cannot be found by index and each skip-eligible child is tested against the dirty path instead. The new selftest mounts that shape with a reused self-triggered counter, asserts the counter updates, and captures the resolution mid-pass to prove the fallback (not the index path) ran. Disabling the fallback fails exactly this fixture.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟡 Changes recommended

Multi-dirty membership remains quadratic, and the reported fixture count is stale.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
Resolved since last review (1)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Use binary search for dirty child index membership

src/​Reactor/​Core/​ChildReconciler.cs:1050

Contains runs once for every skip-eligible child, so linearly scanning _indices makes a pass with n reused children and d dirty siblings perform O(n×d) managed comparisons. Batched sibling updates are supported (the new fixture sets two before one render), and ResolveDirtyChildIndices already sorts this array; use binary search so membership is O(log d).

Contains runs once per skip-eligible child, so a linear scan of several dirty indices cost O(children x dirty). AtAll now sorts its indices and Contains binary-searches them; the sort moved from the resolver into AtAll so the struct owns the invariant it relies on.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The reconciliation paths, fallback behavior, performance floor, documentation, and regression coverage are internally consistent with no unresolved defects found.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

⚡ Reactor perf comparison

Workload: StressPerf.ReactorOptimized StocksGrid · --percent 50 --duration 10 · x64 Release · median of 12 paired runs (2 warmup dropped); Δ is the mean change with a 95% CI · PR head and main built and run interleaved on the same runner.

Regression vs main baseline

Metric main (baseline) This PR Δ (95% CI) Status
Renders/sec ↑ 2.79 2.85 -0.1% 95% CI [-4.0, +3.8] ≈ within noise
Avg Reconcile (ms) ↓ 123.5 123.1 -1.3% 95% CI [-6.3, +3.7] ≈ within noise
Avg Diff (ms) ↓ 111.6 111.2 -0.9% 95% CI [-5.4, +3.6] ≈ within noise
Avg Memory (MB) ↓ 284.9 284.8 -0.2% 95% CI [-0.7, +0.4] ≈ within noise

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 ↑ 16.22 15.87 +0.2% 95% CI [-5.6, +5.9] ≈ within noise
Avg Reconcile (ms) ↓ 36.6 37.2 +1.9% 95% CI [-3.0, +6.8] ≈ within noise
Avg Diff (ms) ↓ 34.1 35.1 +2.1% 95% CI [-3.1, +7.3] ≈ within noise
Avg Memory (MB) ↓ 266.6 266.4 -0.1% 95% CI [-0.4, +0.2] ≈ within noise

Allocation (Reactor) — lower is better

Metric main (baseline) This PR Δ (95% CI) Status
Alloc bytes/render ↓ 5004768 4972837 -1.0% 95% CI [-2.2, +0.2] ≈ within noise
Gen0 GC / 1k renders ↓ 206.90 193.55 -4.2% 95% CI [-11.8, +3.3] ≈ 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 ↑ 20.71 21.34 +3.3% 95% CI [+0.8, +5.9] ✅ improvement
Avg Reconcile (ms) ↓ 15.7 15.2 -2.1% 95% CI [-4.4, +0.2] ≈ within noise
Avg Diff (ms) ↓ 15.5 15.0 -2.1% 95% CI [-4.4, +0.1] ≈ within noise
Avg Memory (MB) ↓ 168.6 169.2 +0.1% 95% CI [-0.4, +0.6] ≈ within noise

Allocation (keyed-list) — lower is better

Metric main (baseline) This PR Δ (95% CI) Status
Alloc bytes/render ↓ 172914 172340 -0.4% 95% CI [-0.7, -0.1] ✅ improvement
Gen0 GC / 1k renders ↓ 9.48 9.17 -3.2% 95% CI [-5.5, -0.9] ✅ improvement

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' OnRenderComplete phase hook, in FlexPanel.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.24 1.24 +0.5% 95% CI [-4.2, +5.2] ≈ within noise
Avg Reconcile (ms) ↓ 162.4 163.9 +0.1% 95% CI [-2.4, +2.5] ≈ within noise
Avg Diff (ms) ↓ 142.5 145.2 +0.9% 95% CI [-1.6, +3.5] ≈ within noise
Avg Memory (MB) ↓ 246.2 246.3 -0.1% 95% CI [-1.3, +1.0] ≈ within noise

Allocation (flex) — lower is better

Metric main (baseline) This PR Δ (95% CI) Status
Alloc bytes/render ↓ 8523412 8510950 +0.3% 95% CI [-0.3, +0.9] ≈ within noise
Gen0 GC / 1k renders ↓ 461.54 461.54 -1.6% 95% CI [-4.5, +1.4] ≈ 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 (#663/#669) and re-allocates the per-realized-cell/row .OnTapped/.OnPointerPressed closures (#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 → coalesced forceRender + 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 ↑ 4.67 4.74 +1.1% 95% CI [-2.2, +4.3] ≈ within noise
Avg Reconcile (ms) ↓ 105.4 103.6 -0.9% 95% CI [-4.3, +2.5] ≈ within noise
Avg Diff (ms) ↓ 105.3 103.5 -0.9% 95% CI [-4.3, +2.5] ≈ within noise
Avg Memory (MB) ↓ 274.5 274.7 -0.2% 95% CI [-0.9, +0.6] ≈ within noise

Allocation (datagrid) — lower is better

Metric main (baseline) This PR Δ (95% CI) Status
Alloc bytes/render ↓ 13812260 13775729 -0.2% 95% CI [-0.7, +0.2] ≈ within noise
Gen0 GC / 1k renders ↓ 166.67 164.97 -0.2% 95% CI [-3.6, +3.2] ≈ 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 #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 ↓ 708.0 78.7 9.0× faster
bytes/recycle ↓ 4,704 176 26.7× 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, Memo returns the same Element instance, so ReferenceEquals holds and Element.CanSkipUpdate is 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 only BuildOrCache). 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
M1 Mount_Leaf_NoCallback 124087.3 -1.0% 95% CI [-3.6, +1.5] 1140.9 0.0% 95% CI [0.0, 0.0] ≈ within noise
M2 Mount_Leaf_OneCallback 98023.5 -5.2% 95% CI [-19.8, +9.3] 3431.3 0.0% 95% CI [0.0, 0.0] ≈ within noise
M3 Mount_Leaf_ThreeCallbacks 221800.4 -1.7% 95% CI [-9.6, +6.1] 8880.5 -0.3% 95% CI [-2.0, +1.3] ≈ within noise
M4 Dispatch_Switch_Cold 113375.2 -3.2% 95% CI [-15.3, +8.9] 1759.8 0.0% 95% CI [0.0, 0.0] ≈ within noise
M5 Dispatch_Switch_Warm 100680.6 +6.6% 95% CI [-7.1, +20.3] 1757.4 -1.1% 95% CI [-2.8, +0.7] ≈ within noise
M6 Dispatch_ExternalType 80603.0 +5.3% 95% CI [-11.1, +21.8] 987.6 -1.9% 95% CI [-5.0, +1.2] ≈ within noise
M7 Update_NoChange 65388.4 +0.8% 95% CI [-0.3, +1.9] 370.1 +9.2% 95% CI [+2.0, +16.5] ≈ within noise
M8 Update_OneLeafChanged 34727.7 +1.5% 95% CI [-2.9, +5.9] 536.0 0.0% 95% CI [0.0, 0.0] ≈ within noise
M9 Update_AllChanged 3297551.2 -0.4% 95% CI [-1.6, +0.9] 184278.1 0.0% 95% CI [0.0, 0.0] ≈ within noise
M10 EventHandlerState_Alloc 64018.3 -2.8% 95% CI [-8.0, +2.4] 3148.3 +0.1% 95% CI [-0.1, +0.3] ≈ within noise
M11 ModifierEHS_Frequency 41522.4 -3.6% 95% CI [-14.5, +7.4] 642.5 0.0% 95% CI [-0.1, +0.1] ≈ within noise
M12 Pool_Rent_HotPath 97107.2 +0.5% 95% CI [-2.1, +3.1] 1099.9 0.0% 95% CI [0.0, 0.0] ≈ within noise
M13 Setters_Suppression_Scope 126.0 -2.2% 95% CI [-17.2, +12.8] 26.7 0.0% 95% CI [0.0, 0.0] ≈ within noise
M14 Dsl_Rebuild_Cascade 1728582.9 -1.1% 95% CI [-3.6, +1.4] 2308628.9 0.0% 95% CI [0.0, 0.0] ≈ within noise
C207 ChangeHandler_DpRead_Coalesce 1311.4 -4.0% 95% CI [-15.7, +7.7] 0.6 0.0% 95% CI [0.0, 0.0] ≈ within noise
OAlloc Optional_Element_Alloc 312.2 -2.4% 95% CI [-19.4, +14.6] 528.0 0.0% 95% CI [0.0, 0.0] ≈ within noise
OUpdate Optional_Reconciler_Update 13445.9 +0.2% 95% CI [-17.1, +17.4] 2852.4 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.49 5.29 2.85
Avg Reconcile (ms) ↓ n/a 22.6 123.1
Avg Diff (ms) ↓ n/a 19.7 111.2
Avg Memory (MB) ↓ 265.1 197.6 284.8

↑ 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 / ⚠️ regression require the CI to exclude 0.
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: AMD EPYC 9V74 80-Core Processor · 4 logical cores · 16 GB RAM · runner: GitHub Actions 1064440375.
Generated by .github/workflows/perf-compare.yml · PR 93628b4 vs main 885a5d8 · 2026-10-01T19:29:31Z · run log.

Resolves a CHANGELOG.md conflict: #1309's Devtools entry and this branch's entry were both added at the same place under Fixed. Both are kept, with the landed entry first.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

Copilot review overview

🟢 Approval recommended

The reconciliation fix is coherent, preserves skip-path performance, and has strong regression and edge-case coverage.

Review effort: Balanced
Findings: None

@azchohfi
Alexandre Zollinger Chohfi (azchohfi) merged commit 28ace24 into main Oct 1, 2026
64 of 66 checks passed
@azchohfi
Alexandre Zollinger Chohfi (azchohfi) deleted the azchohfi-memoized-child-skips-self-rerender branch October 1, 2026 22:27
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