Skip to content

perf(text): Allocate text drawing collections only when used - #25413

Open
MartinZikmund wants to merge 1 commit into
masterfrom
dev/mazi/textdraw-lazy-alloc
Open

MartinZikmund wants to merge 1 commit into
masterfrom
dev/mazi/textdraw-lazy-alloc

Conversation

@MartinZikmund

Copy link
Copy Markdown
Member

GitHub Issue: closes #25412

PR Type:

✨ Feature (performance)

What changed? 🚀

UnicodeText.Draw now only allocates its per-recording collections when the text needs them. Rendering is unchanged.

  • The highlighter RangeSlicer is created only when a highlighter has a non-empty range. Otherwise a single unset segment covers every cluster.
  • The collections for text decorations, decoration lines, spell-check underlines and composition underlines are created on first use, the same way tab leaders and inline-object images already were.

Motivating case: GridView scrolling in #25389, where text is recorded as items scroll into view.

Numbers. Master with and without this change, same commit, Win32 Skia, 3 rounds plus a null copy:

Scroll by steps Before (B/frame) After (B/frame) Change
GridView 20,061 16,491 −18%
ListView 32,615 31,905 −2%

Timings were within noise.

Validation. Runtime tests on Skia desktop: Given_TextBlock, Given_TextBlock_TextDecorations, Given_RichTextBlock (including Highlighters and Render), Given_TextBox, Given_RichEditBox (spell-check and composition underlines) and Given_Hyperlink. 1,601 of 1,603 tests pass and 1 is skipped. The one failure, When_IsTextSelectionEnabled_CRLF, is pre-existing and also fails on master.

No new test: behavior is unchanged, existing tests cover every affected path, and an allocation-threshold runtime test would be flaky.

PR Checklist ✅

🤖 Generated with Claude Code

https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC

Every text recording created a highlighter slicer and empty collections
for decorations, spell-check and composition underlines, though most
text has none of them. They are now created on first use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Vi68uWCYVXxhcX9m6JEwSC
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @MartinZikmund's task in 22s —— View job


Review of #25413: lazy allocation in UnicodeText.Draw

Verdict: ship. I found 0 blocking issues and 0 inline findings.

Code review assessment (by inspection, not executed):

  • Highlighter slicer: The shared s_noHighlighterSegments is equivalent to a fresh, unmarked RangeSlicer(0, _text.Length). Both are one unset segment starting at 0. The shared one ends at long.MaxValue, so the End <= cluster.start advance loop at UnicodeText.cs:1568 never walks past the list. The only observable difference is the segment end for empty text. In that case the cluster loop doesn't run, so it doesn't matter.
  • Mutation safety: The shared segment list is only read through IReadOnlyList, and RangeSlicer.Mark copies into a new list. Sharing it across threads or draws is safe.
  • Lazy collections: Each ??= sits at its only add/assign site, and each draw-time consumer is null-guarded. The AddDecoration(textDecorationLines ??= new(), …) calls are correct because the argument is evaluated before the call. The Draw method doesn't read the lazy collections anywhere else.
  • Style: Tabs, braces and EventHandler rules are respected. There are no new warnings or pragmas, and no platform-suffix concerns because the change is in Skia-only Uno.UI.

Evidence labels:

  • Code review: done, as above.
  • Compile and runtime: I didn't build or run anything. I'm relying on the PR's reported results: 1,601 of 1,603 runtime tests passing on Skia desktop, with When_IsTextSelectionEnabled_CRLF failing the same way on master.

Minor notes (non-blocking):

  • The new s_noHighlighterSegments field sits between two Draw overloads. Moving it to the top of the type, with the other statics, would match convention.
  • The PR checklist has unchecked boxes for runtime tests and docs. The PR explains why no test was added (no behavior change), which is reasonable for a pure perf change. The Screenshots Compare box is still open, so check it before merging.

@unodevops

Copy link
Copy Markdown
Contributor

@nventive-devops

Copy link
Copy Markdown
Contributor

The build 239333 found UI Test snapshots differences: skia-linux-screenshots: 118, skia-windows-screenshots: 2458

Details
  • skia-linux-screenshots: 118 changed over 2458

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • ButtonClippingTestsControl.png-dark
    • ButtonClippingTestsControl.png
    • Buttons.png-dark
    • Buttons.png
    • ClipboardTests.png-dark
    • CalendarView_Theming.png-dark
    • CalendarView_Theming.png
    • CompositionEffectBrush.png-dark
    • CompositionEffectBrush.png
    • CompositionNineGridBrush_Source_Changes.png-dark
    • CompositionNineGridBrush_Source_Changes.png
    • DisplayInformation.png-dark
    • Examples.png
    • Focus_FocusVisual_Properties.png-dark
    • Focus_FocusVisual_Properties.png
    • DoubleImageBrushInList.png-dark
    • DoubleImageBrushInList.png
    • ImageBrushAlignmentXY.png-dark
    • ImageBrushAlignmentXY.png
    • DynamicFont.png-dark
  • skia-windows-screenshots: 2458 changed over 2488

    🚨🚨 Comparison Details (first 20) 🚨🚨
    • AndroidWindowInsets.png-dark
    • AnimatedIconPage.png-dark
    • AppBarButtonTest.png
    • AppBar_KeyBoard.png-dark
    • ApplicationViewSpanningRectsPage.png-dark
    • AppWindowClosing.png
    • AppWindowPresenters.png
    • Arrange_Performance01.png
    • Attributed_text_Simple.png-dark
    • Attributed_text_Simple.png
    • AutoBorderStretchwithrightmargin.png-dark
    • AutoBorderStretchwithrightmargin.png
    • AutomationProperties_StructureAndProps.png
    • AutoSizedPathCentered.png-dark
    • BackGesture.png-dark
    • BackGesture.png
    • Basics Pivot Test.png
    • Basics.png-dark
    • BeginTime_MultipleAnimations.png
    • BenchmarkDotNet.png-dark

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 239333 has failed on Uno.UI - CI.

@MartinZikmund MartinZikmund added the 7.1 PRs only. For issues, use the Release field. label Oct 14, 2026
MartinZikmund added a commit that referenced this pull request Nov 2, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 2, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 9, 2026
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 morning4coffe-dev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that every lazily created collection is only filled at its ??= site and that every reader null-checks it. The shared s_noHighlighterSegments behaves like an unmarked RangeSlicer(0, _text.Length) for the cluster walk, since its end is long.MaxValue and nothing mutates it. This is Skia draw bookkeeping with no WinUI counterpart, and behavior is unchanged. LGTM.

@mergify

mergify Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request

MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 13, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 14, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 17, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
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
MartinZikmund added a commit that referenced this pull request Nov 18, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

7.1 PRs only. For issues, use the Release field.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text drawing allocates highlighter and decoration collections on every recording

4 participants