Skip to content

refactor: rename Factories.Text → TextBlock, TextElement → TextBlockElement - #35

Merged
Chris Anderson (codemonkeychris) merged 2 commits into
mainfrom
refactor/text-to-textblock-rename
Apr 19, 2026
Merged

Chris Anderson (codemonkeychris) merged 2 commits into
mainfrom
refactor/text-to-textblock-rename

Conversation

@codemonkeychris

Copy link
Copy Markdown
Collaborator

Summary

Renames the Reactor DSL text factory and its element record for consistency with WinUI's own naming:

  • Factories.Text → TextBlock (the DSL factory method)
  • TextElement → TextBlockElement (the element record)
  • All Factories.Text(...) call sites collapse to bare TextBlock(...) via using static

Scope

353 files changed (~3,178 / ~3,169 insertions/deletions):

  • src/Reactor/Core/Element.cs — renamed the TextElement record
  • src/Reactor/Elements/Dsl.cs — renamed the Text factory method and its return type across Heading / SubHeading / Caption
  • src/Reactor/Core/Reconciler.cs — updated the two pattern matches in ExtractElementCaption / ResolveCaptionForElement that resolve caption-derived automation names
  • src/Reactor.Cli/Loc/LocalizableStringScanner.cs — DSL method table updated ("Text" → "TextBlock")
  • src/Reactor/Controls/Validation/FormField.cs + 8 tests — added using static Microsoft.UI.Reactor.Factories; where call sites previously used the Factories. qualifier
  • 25 sample / test / docs-pipeline files — bare Text(...) DSL calls renamed to TextBlock(...)
  • Docs (SKILL.md, CONTRIBUTING.md, skills/*.md, skills/design-docs/*.md) and regenerated docs/guide/*.md updated for naming consistency
  • tests/Reactor.AppTests.Host/SelfTest/Fixtures/DevtoolsFixtures.cs — carried over during rebase onto the new devtools phase 1 merge

Naming-conflict analysis (pre-change)

Verified before starting:

  • No existing TextBlock factory method on Factories
  • No existing TextBlockElement type anywhere in the codebase
  • Coexistence with WinUI's Microsoft.UI.Xaml.Controls.TextBlock type is fine — a method and a type can share a name in C# because invocation context disambiguates (TextBlock(...) binds to the method, new TextBlock() / typeof(TextBlock) / type-position references bind to the WinUI type)
  • Did not rename the unrelated Microsoft.UI.Xaml.Documents.TextElement WinUI type

Test plan

All three test suites per CONTRIBUTING.md:

  • Unit tests (dotnet test tests/Reactor.Tests) — 3,859 passed, 0 failed, 46 skipped
  • Selfhost tests (dotnet run --project tests/Reactor.AppTests.Host -- --self-test) — 423 fixtures, 1,612 TAP asserts, 0 failures
  • E2E tests (dotnet test tests/Reactor.AppTests) — 105 passed, 1 failed. The single failure is Interactive_DataGrid_ClickEditTabCommit, which reproduces identically on main with no rename changes. Tracked as DataGrid cells lost from UIA tree after async commit triggers row state transition #34.

Notes for reviewers

  • The rebase onto main picked up the 024 devtools phase 1 merge; two fresh TextElement references in Reconciler.cs and nine Factories.Text references in the new DevtoolsFixtures.cs were renamed in place.
  • Docs were recompiled with mur docs compile --no-screenshots to keep docs/guide/*.md in sync with the renamed DSL. No screenshot regeneration.

🤖 Generated with Claude Code

…ckElement

Renames the Reactor DSL text factory and its element record for clarity. All
Factories.Text call sites collapse to bare TextBlock() via using-static.
Localization scanner DSL table and its tests updated to match the new method
name. Added using-static Factories to 9 files that previously relied on the
Factories. qualifier.

Co-Authored-By: Claude Opus 4.7 (1M context) <[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.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@codemonkeychris
Chris Anderson (codemonkeychris) merged commit 4ccc106 into main Apr 19, 2026
3 checks passed
@codemonkeychris
Chris Anderson (codemonkeychris) deleted the refactor/text-to-textblock-rename branch April 19, 2026 03:12
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 26, 2026
Hot keyed list-diff path (grid steady state) allocated heavily and missed
fast-paths even when keys were unchanged. Eliminate per-diff allocations and
add the missing fast-path, preserving diff behavior exactly.

ChildReconciler.cs:
- Keyed prefix/suffix loops now take the Element.CanSkipUpdate early-exit
  that the positional path has, so stable keyed rows no longer re-diff every
  tick (#30); cache children.Count once instead of re-reading the COM
  IVector.get_Size per suffix iteration (#37).
- Replace HashSet-returning ComputeLIS with allocation-free ComputeLISInto
  filling a pooled bool mask; pool tails/tailIndices/predecessors from
  ArrayPool (#31/#32). Keep a thin ComputeLIS(int[]) wrapper for tests.
- Pool ReconcileKeyedMiddle's working arrays (ArrayPool) and the two
  key->index maps (re-entrancy-safe ThreadStatic dict pool); buffers cleared
  and returned on every exit (#33).
- Filter: count-pass + single Element[] fill, no List+ToArray (#36).
- GetKey: cache Type.Name via ConcurrentDictionary (#38).

KeyedListDiff.cs:
- Rent newKeys from ArrayPool<string>, threading explicit newCount (rented
  array may be larger); returned clearArray:true in a finally (#2).
- Move the no-op (SequenceEqual) + empty/empty fast paths ABOVE the duplicate
  scan so the steady-state grid case never allocates/scans a dup set (#1).
- Fold the churn-bailout decision into ApplyGeneral, computed from the same
  post-prefix/suffix scratch map the general walk builds (diff-range churn ==
  full-range churn), removing the O(2n) null-marker pre-pass (#34).
- Pool the doomed ReactorRow[] (ArrayPool, descending IComparer sort over
  [0,removes), cleared+returned) (#3).
- Lazy-allocate movedRows only on an actual move under an ambient (#35).
- In-place SyncLastKeysToSource instead of LastKeys Clear()+Add (#10).
- HasDuplicates reuses state.Scratch (TryAdd) for 4+ keys instead of a fresh
  HashSet (#11); cached null-key diagnostic sample (#41).

Tests: add pooling non-corruption coverage (rented-buffer-larger-than-count,
interleaved independent states, randomized stress vs oracle with survivor
identity, pooled doomed removes, churn with shared prefix+suffix, Scratch
reuse for the dup scan) and ComputeLISInto bool-mask coverage. Full
Reactor.Tests suite green (9693 passed); core lib Release build is
warning-clean (AOT/trim).

Closes #653

Co-authored-by: Copilot <[email protected]>
Alexandre Zollinger Chohfi (azchohfi) added a commit that referenced this pull request Jun 27, 2026
…ff (#657)

* perf: eliminate per-diff allocations in ChildReconciler + KeyedListDiff

Hot keyed list-diff path (grid steady state) allocated heavily and missed
fast-paths even when keys were unchanged. Eliminate per-diff allocations and
add the missing fast-path, preserving diff behavior exactly.

ChildReconciler.cs:
- Keyed prefix/suffix loops now take the Element.CanSkipUpdate early-exit
  that the positional path has, so stable keyed rows no longer re-diff every
  tick (#30); cache children.Count once instead of re-reading the COM
  IVector.get_Size per suffix iteration (#37).
- Replace HashSet-returning ComputeLIS with allocation-free ComputeLISInto
  filling a pooled bool mask; pool tails/tailIndices/predecessors from
  ArrayPool (#31/#32). Keep a thin ComputeLIS(int[]) wrapper for tests.
- Pool ReconcileKeyedMiddle's working arrays (ArrayPool) and the two
  key->index maps (re-entrancy-safe ThreadStatic dict pool); buffers cleared
  and returned on every exit (#33).
- Filter: count-pass + single Element[] fill, no List+ToArray (#36).
- GetKey: cache Type.Name via ConcurrentDictionary (#38).

KeyedListDiff.cs:
- Rent newKeys from ArrayPool<string>, threading explicit newCount (rented
  array may be larger); returned clearArray:true in a finally (#2).
- Move the no-op (SequenceEqual) + empty/empty fast paths ABOVE the duplicate
  scan so the steady-state grid case never allocates/scans a dup set (#1).
- Fold the churn-bailout decision into ApplyGeneral, computed from the same
  post-prefix/suffix scratch map the general walk builds (diff-range churn ==
  full-range churn), removing the O(2n) null-marker pre-pass (#34).
- Pool the doomed ReactorRow[] (ArrayPool, descending IComparer sort over
  [0,removes), cleared+returned) (#3).
- Lazy-allocate movedRows only on an actual move under an ambient (#35).
- In-place SyncLastKeysToSource instead of LastKeys Clear()+Add (#10).
- HasDuplicates reuses state.Scratch (TryAdd) for 4+ keys instead of a fresh
  HashSet (#11); cached null-key diagnostic sample (#41).

Tests: add pooling non-corruption coverage (rented-buffer-larger-than-count,
interleaved independent states, randomized stress vs oracle with survivor
identity, pooled doomed removes, churn with shared prefix+suffix, Scratch
reuse for the dup scan) and ComputeLISInto bool-mask coverage. Full
Reactor.Tests suite green (9693 passed); core lib Release build is
warning-clean (AOT/trim).

Closes #653

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

* perf: address PR review on keyed-diff allocation fixes

Review follow-ups on #657 (keyed list-diff allocation work):

- ChildReconciler.ReconcileKeyedMiddle: return the pooled matched and inLis
  bool[] buffers with clearArray:false instead of true (Copilot review).
  Both are value-typed (no reference pinning) and have their used range
  fully (re)initialized before any read - matched via the Array.Clear on
  rent, inLis via ComputeLISInto leading clear - so the full-array wipe on
  return was avoidable O(rented-capacity) work on the hot path. Matches how
  the int[] newToOld already returns. Reference-typed pooled buffers
  (string[]/ReactorRow[] in KeyedListDiff) still clear.

- Tests (ChildReconcilerLisIntoTests): replace the circular oracle that
  compared ComputeLISInto against ComputeLIS (now a thin wrapper over it)
  with an independent brute-force LIS-length DP that honors the -1 unmapped
  sentinel, asserting the mask marks a valid strictly-increasing subsequence
  of maximal length.

- Tests (ChildReconcilerKeyedSkipTests, new): cover the #30 keyed
  CanSkipUpdate fast path - an identical keyed list skips every row with no
  ops and no child-control access, across repeated stable frames.

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

* fix: correct keyed-middle reorder identity (C1/H1) + reorder & alloc tests

The keyed-middle reconciliation in ChildReconciler patched surviving
controls by their FINAL panel index while the panel was only partially
rearranged, so on reorders a survivor was patched against the wrong
control (C1, CRITICAL): e.g. rotation [a,b,c,d]->[b,c,d,a] rendered "c"
at slot 0 and scrambled keyed identity (focus/animation/state landed on
the wrong row). A related stale keyToIndex (only the moved key was
rewritten) left shifted siblings mis-indexed after an insert/move (H1).

Fix: extract the index logic into RunKeyedMiddleCore<TSink> behind a
struct-generic IKeyedMiddleSink seam (devirtualized, AOT-clean) and
replace the left-to-right loop with the canonical right-to-left LIS walk.
Each item is positioned immediately before its already-placed right
neighbour; LIS members stay put and only out-of-LIS movers relocate
(minimal moves). Every survivor is patched at its CURRENT live position,
resolved from a pooled oldRelToPanel int[] that is mutated in lock-step
with every Insert/Move so it stays exact -- fixing C1 and H1 together.
The production RealKeyedMiddleSink drives the identical Mount/Move/
UpdateChild/Unmount/Replace + ambient enter/move behaviour as before.
oldRelToPanel replaces the second pooled key->index dict (one fewer
rented dict per call).

Tests:
- ChildReconcilerKeyedMiddleCoreTests (new): a headless SimKeyedMiddleSink
  drives the SAME RunKeyedMiddleCore over identity cells (exact production
  parity, no live-WinUI selftest wall), with a 4-invariant oracle (length,
  prefix/suffix untouched, per-slot identity+content, every patch hits its
  claimed survivor) across rotation, full reverse, scramble, block-swap,
  inserts/removes/duplicates and prefix/suffix offsets. A faithful
  pre-fix reproduction proves the rotation regression test has teeth (the
  buggy walk corrupts content[0] and mis-patches; the real core is clean).
- KeyedListDiffPoolingTests: two GC.GetAllocatedBytesForCurrentThread
  budgets guarding the #1/#2/#11 pooling -- no-op steady-state diff is
  0 B/iter and a 128-key reorder is 72 B/diff; reverting the pooling
  (a new string[128] + a 128-entry HashSet per diff) fails them.

Diff correctness preserved; pooled buffers returned on every exit.

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

* fix: gate keyed no-op fast path on duplicate-free state + test hardening

Address Copilot re-review of e664f9f.

KeyedListDiff: the no-op fast path runs above the duplicate scan (#1), so
an UNCHANGED list that already holds duplicate keys -- the state a prior
duplicate bailout leaves behind, since ReactorListState.Reset preserves
the dups in Source/LastKeys but collapses ByKey to first occurrences --
would match LastKeys and return Empty, silently skipping the duplicate
bailout/diagnostic and leaving the diff in an invalid duplicate state.
Gate the fast path on `state.ByKey.Count == oldCount`: true exactly for
the duplicate-free steady state (allocation-free path preserved), false
when dups were collapsed (re-takes the bailout). The check is O(1) and
short-circuits before the O(n) SequenceEqualOrdinal, so the common
unique-key path pays nothing. No-op steady-state allocation stays 0 B/iter.

Tests:
- KeyedListDiffTests: new Apply_Unchanged_Duplicate_List_Re_Bails_Instead_
  Of_NoOp_FastPath -- proves an unchanged duplicate list re-bails; verified
  to FAIL without the guard (takes the no-op path and returns Empty).
- ChildReconcilerLisIntoTests: strengthen the LIS oracle to assert selected
  indices are never the unmapped -1 sentinel (a buggy impl could swap a real
  member for a -1 and still satisfy strictly-increasing + length).
- KeyedListDiffPoolingTests: drop the unused `using System.Buffers;`
  (fully-qualify the one ArrayPool cref) flagged by the reviewer.

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

---------

Co-authored-by: Copilot <[email protected]>
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