Repository navigation
Description
Background
A perf scan measured a large C# vs Rust gap on the data-grid stress workload (tests/stress_perf/StressPerf.ReactorOptimized, a StocksGrid). The dominant gap is Reconcile (~46ms C# vs ~7.9ms Rust, ~5.8x), driven largely by the diff/patch path repeatedly crossing the COM/RCW boundary and allocating per element.
Each WinRT control access — GetValue on attached DPs, RCW type-tests (is FrameworkElement), AutomationProperties reads — is expensive, and the reconciler currently repeats several of these per element, per frame. This issue tracks coalescing those redundant reads and removing per-element allocations on the reconcile/patch path.
Scope (files): src/Reactor/Core/Reconciler.cs, Reconciler.Update.cs, Reconciler.Mount.cs, Reconciler.KeyedItemsBinding.cs, AccessibilityScanner.cs (plus minimal Context/ContextScope/ComponentNode plumbing the fixes require). Behavior must be preserved exactly — coalesced COM reads must observe the same values at the same times; unmount/cleanup ordering is unchanged; the accessibility scanner must emit identical findings.
Flagship findings (attack the Reconcile gap directly)
- Implement async resources (spec 020): AsyncValue + UseResource / UseInfiniteResource / UseMutation #14
Reconciler.Update.cs— five separateis FrameworkElementtype-tests on the sametargetper updated element. Coalesce to onevar targetFe = target as FrameworkElement;and reuse. - Reorganize docs/ folder per spec 021 #15
Reconciler.cs CreateComponentRerender— allocates a newActionclosure everyReconcileComponent(per stateful row/cell per frame). Cache the wrapped delegate on theComponentNode; recreate only when therequestRerenderidentity changes. - Give the AI agent 'eyes': make build → view → iterate efficient for AI-driven development #16
Reconciler.cs UnmountRecursive— readsReactorAttached.StateProperty(viaGetElementTag) 5× on the same control per removed cell. Read once at the top, reuse. - Scrub the list of samples #17
Reconciler.cs UnmountAndCollect— 5 independentGetElementTagCOM calls on the same control. Read once, reuse.
Other reconcile/patch findings
- Test suite cleanup: isolate selftest from e2e, remove noise, unify coverage reporting #18
UpdateDefaultAutomationName—AutomationProperties.GetNameCOM read for every captioned element pastShallowEquals. Skip the redundantSetNamewrite when the value is unchanged (provenance prevents safely skipping the read). - Reframe README as WinUI/XAML landing page; refresh CONTRIBUTING #19
Reconciler.Update.cs—modifiers ?? new ElementModifiers()allocates a fresh object per clear-modifiers update. Acceptnull= clear-all via a cached empty singleton. - ci: skip unit tests on Markdown-only changes #20
PopulateDirtyAncestorPath— iterates the entire_componentNodesdict everyReconcile. Track a set of self-triggered nodes and iterate only those. - Add spec 022: packaging and distribution #21
UnmountAndPool— allocatesnew List<FrameworkElement>()per call. Reuse a cleared field/thread-local list. - Ship Reactor as a consumable package (NuGet + CLI) #22
RefreshRealizedContainers— snapshotsnew List<UIElement>(count)per call (~3000/sec at 50 rows@60Hz). Reuse a cleared field list. - docs(021): execute docs folder reorganization #23
ApplyStyleToElement— setsStyle=nullthenStyle=cachedunconditionally (2 COM DP writes + visual-state re-eval) even when unchanged;ApplyThemeBindingsruns on theShallowEqualsskip branch every render. Guard on style ref and effective theme (the null-then-set is only load-bearing when the effective theme changed); make the fast-path cheap. - Add spec 023: performance insight tools #24
BuildCacheKey—bindings.Keys.ToArray()+ newStringBuilder+ double dict lookup per themed cell per frame. Cache the key on the bindings ref; reuse a thread-localStringBuilder; single iteration. - Investigate and implement spec 023: Performance Insight Tools #25
HasConsumedContextChanged—object.Equalsboxes value-type context values. Compare via typedContext<T>/EqualityComparer<T>.Default. - docs(020): refine async resources spec after design review #26
ApplyResourceOverrides—AllKeys.ToHashSet()+managed.ToArray()per cell per update. Iterate without materializing; linear scan small sets; ref-equal fast-path. - docs(023): add PERF006/PERF007 from perf-team feedback #27
WireReferenceListEdge— allocatesList+Any(lambda)closures per ref-edge. Static loop with a local ref. - docs(024): add AI agent devtools spec #28
ApplyStaggerDelays— allocatesnew string[6]per staggered child. Hoist to a static readonly array. - Async resources: AsyncValue / QueryCache / UseResource / UseInfiniteResource / UseMutation + DataGrid hook-paging + analyzers #29
PushContextDisposable— allocatesDictionary(1)+PopOnDisposeper context push. Single-pair push overload. - feat(25): CLI parity surface for devtools MCP #39
Reconciler.KeyedItemsBinding.cs—new ClosureItemViewSource+SetItemViewSource(COM) every bind even when items/builder unchanged. Ref-equality cache; only realloc + set on change. - test: isolate unit/selftest/e2e into 3 distinct projects (#18) #40
Reconciler.Mount.cs—LayoutFootgunDetector.Inspectcalled per mounted element. Hoist the flag read.
Accessibility scanner (reconcile scan walk)
- Show selftest progress on Windows taskbar icon #62
ScanContext.PushandWalkboth callGetChildren(el)— two switch dispatches per element. Compute once inWalk, pass intoPush. - Add property inspection, resource browsing, and style inspection devtools #63
GetSiblingTextsdoesCurrentSiblingTexts.ToArray()at 5 emit sites. Cache the sibling array inScanContext, invalidate onPush. - docs(research): sync overview comparison with latest critical review #64
BuildContextruns 3 LINQ chains per finding. Single foreach pass, pre-sized arrays. - Add navigation, forms, and input skill files; expand accessibility section #65
IsLikelyEmojiusestext.Any/AllLINQ per Button label. Explicit span loop. - Spec 029: TreeGrid control and DataGrid grouping #66
CheckTabIndexGapsOrderBy+ToList. Sort a local/rented array. - Bump WindowsAppSDK to 2.0.0-preview2 #67 eager interpolated
Message+Truncatebuilt per finding. Defer where feasible without changing the publicA11yDiagnosticcontract.
Expected impact
Removes the bulk of redundant COM round-trips and per-element allocations on the reconcile/patch path, directly reducing the ~5.8x Avg Reconcile gap and the ~39ms Avg Diff. Validated via /perf (benchmarks vs main) once that workflow merges.
Definition of done
Build (dotnet build Reactor.slnx -c Release) + unit tests (dotnet test tests/Reactor.Tests) green; mount/update/unmount selftests pass; new xUnit coverage for the rerender-delegate caching, context-change comparison, and scanner output parity.
Activity
perf: address PR review findings (behavior-parity hardening + tests)
perf: coalesce COM-interop reads + allocations in reconcile path
perf: address PR review findings (behavior-parity hardening + tests)
azchohfi commentedon Jul 1, 2026
Closing as not planned — below the measurement bar. #666 implemented the full COM-interop coalescing set with behavior-parity tests but was closed as an honest no-op: the effect measures below
/perfharness resolution on all macro workloads (StocksGrid, KeyedList, DataGrid), and the earlier skip-floor regression did not reproduce. #769 independently re-validated on currentmainand the no-op verdict holds. The optimizations are real (behavior-preserving) but not resolvable on current workloads. Reopen if a COM-interop-heavy workload is added that can surface the effect.