Repository navigation
perf(textblock): Keep a single line's layout under a new constraint - #25411
MartinZikmund wants to merge 4 commits into
Conversation
A TextBlock measured again only because its parent offered another size re-parsed and re-shaped its text every time. A single unwrapped, untrimmed line has the same lines and size under any constraint, so measure now keeps the current layout and arrange positions it, as it already did. A TextBlock invalidated since its last layout is laid out as before. 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
A text change made while the block measures itself, or while invalidations are intercepted, now also keeps the next measure from reusing the layout. 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 19s —— View job Review summaryVerdict: ship, with one nit.
What I checked (code review only, no build or runtime run):
Cross-cutting: reuse depends on every text-affecting change reaching |
| // Whether the text was invalidated since it was last laid out, as opposed to only being measured under a new constraint. | ||
| private bool _isMeasureInvalidated = true; | ||
|
|
||
| private protected override void OnMeasureInvalidated() => _isMeasureInvalidated = true; |
There was a problem hiding this comment.
Nit: the new flag and override are wedged between _textLayoutVersion and _textLayoutWidth, splitting the layout-state fields. Move _textLayoutWidth above them, or put the override with the other methods, so the fields stay grouped.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25411/wasm-skia-net9/index.html |
|
The build 239328 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.
WinUI does the same in ParagraphNode::CanBypassMeasure: NoWrap text with TextTrimming None skips re-measure when only the width changes, and wrapping or trimming forces it. IsSizeValidFor matches that, and leaving Justify out follows WinUI's own note there. A possible follow-up is WinUI's second bypass case, wrapping text whose untrimmed desired width still fits when the available width shrinks, which is the common "container shrank but text still fits" case. One small ordering note inline.
| _textLayoutVersion++; | ||
| } | ||
|
|
||
| _isMeasureInvalidated = false; |
There was a problem hiding this comment.
Clearing the flag after ParseText loses any InvalidateMeasure raised during the parse, for example a font-loaded callback from fallback resolution, which can now complete synchronously for local fonts. The layout system ignores that invalidation while measuring, so with this reset the next constraint-only measure would reuse the stale parse. Could you capture and clear it before parsing instead (var invalidated = _isMeasureInvalidated; _isMeasureInvalidated = false; ...)?
|
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 #25410
PR Type:
✨ Feature (performance)
What changed? 🚀
A TextBlock measured again only because its parent offers a different constraint now keeps its text layout when the layout can't depend on that constraint: a single unwrapped, untrimmed, unjustified line with no paragraph layout. Measure returns the existing size and arrange positions the line, as it already did. A TextBlock whose own measure was invalidated since its last layout is re-parsed as before.
UnicodeText.IsSizeValidForis the size counterpart ofIsLayoutValidFor. Alignment and right-to-left only offset the line, so they don't count as width dependencies.UIElement.OnMeasureInvalidated(private protected) is a new hook. It is called on everyInvalidateMeasure, including ones ignored because the element is measuring itself or invalidations are intercepted, and when Enter dirties measure. TextBlock uses it to know whether a new measure is a pure constraint change.Motivating case: #25389. Its
ListViewItemPresentermulti-select check glyph gets a different constraint on every selection toggle and was re-shaped twice per toggle. This also applies to TextBlocks in Grid star columns and to any other multi-pass layout.Numbers. GridView multi-select, toggling 100 items per op (Win32 Skia, 3 rounds plus a null copy, stacked on #25389 and the other open perf PRs):
Validation. Runtime, Skia desktop:
Given_TextBlocktests:Given_TextBlock,Given_TextBlock_TextScaling,Given_RichTextBlock,Given_TextBox,Given_Button,Given_ComboBox,Given_Grid,Given_StackPanel,Given_ToolTip,Given_ContentPresenter,Given_ScrollViewer,Given_FrameworkElement*. 1,314 of 1,323 pass.When_ComboBox_MinWidth,When_IsTextSelectionEnabled_CRLF, andEVP_When_ConstrainedInNonScrollableSV×4 (150% display scale).PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC