Repository navigation
perf(textblock): Repaint a foreground change without a new layout - #25409
MartinZikmund wants to merge 4 commits into
Conversation
A Foreground change on a TextBlock or one of its runs, including a brush color change, invalidated measure, so the text was shaped again. In WinUI a brush change only repaints. The laid-out runs now take the new brushes and the block is repainted; anything that no longer matches the layout falls back to the full invalidation. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
The runs are only updated when no measure is pending, as a new layout starts from inlines that may no longer match them. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
|
Claude finished @MartinZikmund's task in 21s —— View job Review of #25409Verdict: looks good to merge. I found no blocking issues, so I left no inline comments. Findings by severity: 0 blocking, 0 major, 0 minor. I reviewed the diff by inspection only. I did not build or run anything. What I checked
Cross-cutting notes
|
| /// <returns>False when the inlines no longer match the runs, or an ending paragraph marker paints with the default foreground.</returns> | ||
| internal bool TryUpdateForegrounds(Inline[] inlines, Brush? defaultForeground) | ||
| { | ||
| if (!ReferenceEquals(defaultForeground, _defaultForeground) && _endingParagraphLayout is { MarkerText.Length: > 0 }) |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25409/wasm-skia-net9/index.html |
|
The build 239311 found UI Test snapshots differences: Details
|
|
|
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
The implicit GridViewItem style is BasedOn DefaultGridViewItemStyle again, as in WinUI, so default GridView items render through the ListViewItemPresenter chrome and default to AllowDrop=True. The Fluent GridViewItemExpanded is removed. Merge after #25403, #25404, #25406, #25409, #25411 and #25413. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
morning4coffe-dev
left a comment
There was a problem hiding this comment.
This matches WinUI. In dxaml/xcp/core/text/TextBlock/TextBlock.cpp, a TextBlock_Foreground change only calls InvalidateRender, and an inline or inherited Foreground change does the same. The fallbacks look safe: a pending measure, a custom layout, a run-count mismatch and a marker painted with the default foreground all take the full path. One non-blocking perf note inline.
| base.OnForegroundChanged(); | ||
| InvalidateInlinesForFormatChange(); | ||
|
|
||
| if (GetOwningTextBlock() is not { } textBlock || !textBlock.TryUpdateForegrounds()) |
There was a problem hiding this comment.
Non-blocking. When the TextBlock's Foreground changes, every Run that inherits it lands here, and each TryUpdateForegrounds walks the whole leaf tree after the TextBlock's own callback already did one walk, so it's O(n^2) in the number of runs. Fine for typical text, but it adds up with large inline sets. Marking foregrounds stale and applying them once (from the TextBlock callback or before the next draw) would avoid it.
|
Tick the box to add this pull request to the merge queue (same as
|
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GridView stays on GridViewItemExpanded until its perf PRs (#25403, #25404, #25406, #25409, #25411, #25413) land. Apps opt into WinUI's chrome with DefaultGridViewItemStyle. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TXMNu2NWgGKJFTAYtNHkvT
GitHub Issue: closes #25408
PR Type:
✨ Feature (performance)
What changed? 🚀
A
Foregroundchange on aTextBlockor one of its runs (including Spans and Hyperlinks) now repaints the text instead of laying it out again. This covers changing the property and changing a brush's color in place. It matches WinUI, where a brush change only dirties render.UnicodeText.TryUpdateForegroundspoints the laid-out runs at the current inline brushes. Draw already reads those brushes on every paint.TextBlock.OnForegroundChangedandRun.OnForegroundChangedtry that update first. They fall back to the old measure invalidation when:RichTextBlock is unchanged: its own
Foregroundalready only repaints, and Run changes inside a RichTextBlock keep the full path.Numbers. Win32 Skia, Release, 3 rounds plus a null copy. Workload: flip the color of one
SolidColorBrushshared by 2,000 TextBlocks.The synchronous part grows from 0.44 to 1.56 ms, because the brush update runs inline instead of only invalidating.
Motivating case: #25389. Its
ListViewItemPresenterchrome sets the multi-select check glyph'sForegroundon every selection change.Validation (runtime, Skia desktop).
Given_TextBlocktests: property change, brush color change, inherited change across Run, Span and a locally-brushed Run, and Text plus Foreground changed in the same tick. The 3 no-relayout tests fail on master.Given_TextBlock,Given_RichTextBlock*,Given_TextBlock_TextDecorations,Given_TextBox,Given_Hyperlink*,Given_Button,Given_ComboBox. 650 of 653 tests pass and 1 is skipped. The 2 failures are pre-existing:When_ComboBox_MinWidthandWhen_IsTextSelectionEnabled_CRLFfail identically on master.PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC