Repository navigation
Description
Current behavior 🐛
Unmeasured, suspected perf regression, confirmed by code inspection only (no benchmark or runtime repro).
In the managed VirtualizingPanelLayout, the "first/last materialized item" accessors are full scans over every materialized line (and every item in each line), and they are called inside the FillBackward / FillForward loop conditions. Each loop iteration pays O(materialized lines) several times, so one fill pass is O(lines^2) instead of O(lines).
Scans on master (951b7b4):
GetFirstMaterializedIndexPath()/GetLastMaterializedIndexPath(): nested loop over_materializedLines[i].Items,uno/src/Uno.UI/UI/Xaml/Controls/ListViewBase/VirtualizingPanelLayout.managed.cs
Lines 1107 to 1144 in 951b7b4
private Uno.UI.IndexPath? GetFirstMaterializedIndexPath() { var reorderIndex = GetAndUpdateReorderingIndex(); Uno.UI.IndexPath? lowest = null; for (var i = 0; i < _materializedLines.Count; i++) { foreach (var (_, index) in _materializedLines[i].Items) { if (index != reorderIndex && (lowest is null || index < lowest)) { lowest = index; } } } return lowest; } /// <summary> /// The highest materialized item index, ignoring the item being dragged. See <see cref="GetFirstMaterializedIndexPath"/>. /// </summary> private Uno.UI.IndexPath? GetLastMaterializedIndexPath() { var reorderIndex = GetAndUpdateReorderingIndex(); Uno.UI.IndexPath? highest = null; for (var i = 0; i < _materializedLines.Count; i++) { foreach (var (_, index) in _materializedLines[i].Items) { if (index != reorderIndex && (highest is null || index > highest)) { highest = index; } } } return highest; } GetItemsStart()/GetItemsEnd(): loop over all lines,uno/src/Uno.UI/UI/Xaml/Controls/ListViewBase/VirtualizingPanelLayout.managed.cs
Lines 1150 to 1190 in 951b7b4
private double? GetItemsStart() { double? start = null; for (var i = 0; i < _materializedLines.Count; i++) { var lineStart = GetMeasuredStart(_materializedLines[i].FirstView); if (start is null || lineStart < start) { start = lineStart; } } return start; } /// <summary> /// The bottommost (rightmost) materialized pixel, i.e. the maximum measured end over all materialized /// lines. See <see cref="GetItemsStart"/>. /// </summary> private double? GetItemsEnd() { double? end = null; for (var i = 0; i < _materializedLines.Count; i++) { var lineEnd = GetMeasuredEnd(_materializedLines[i].LastView); if (end is null || lineEnd > end) { end = lineEnd; } } if (end is not null) { return end; } // This will be null except // * immediately after ScrapLayout(), where it will be the previous start of materialized items // * during OnScrollChanged if isLargeScroll, where it will be the start of a new layout after all the lines were cleared return _dynamicSeedStart; }
Call sites in the fill loops:
FillBackward: evaluatesGetItemsStart()andGetFirstMaterializedIndexPath()every iteration,uno/src/Uno.UI/UI/Xaml/Controls/ListViewBase/VirtualizingPanelLayout.managed.cs
Lines 546 to 554 in 951b7b4
void FillBackward() { while ( GetItemsStart() is { } start && start > ExtendedViewportStart + extentAdjustment && GetNextUnmaterializedItem(Backward, GetFirstMaterializedIndexPath()) is { } nextItem) { AddLine(Backward, nextItem); } } FillForward: evaluatesGetItemsEnd()andGetLastMaterializedIndexPath()every iteration, same file L555-L565AddLinealso callsGetContentStart()/GetContentEnd()(which wrap the two scans) per added line.
The first/last index accessors used to be O(1) (GetFirstMaterializedLine()?.FirstItem / GetLastMaterializedLine()?.LastItem). They became scans in 78b5a54 (part of #23946), a correctness fix: while a drag-reorder is in progress the dragged item's line is appended to the back of the deque regardless of its index, so the deque is not index-sorted and positional reads returned the wrong index. GetFirstMaterializedLine() / GetLastMaterializedLine() stayed positional (L1072-L1074).
Expected behavior 🎯
Per-iteration cost of the fill loops should not grow with the number of materialized lines. The scan is only needed while a reorder has broken the deque ordering; otherwise the ends of the deque are the extremes.
How to reproduce it (as minimally and precisely as possible) 🔬
Not reproduced at runtime; this is a complexity argument from the source above. A benchmark that would confirm or refute it:
- Create a Skia app with a
ListViewusing small fixed-height items (e.g. 10pxBorders) in a tall viewport, so several hundred lines are materialized. - Scroll in small steps, measuring UI-thread time per scroll step (or count calls to the four accessors per fill pass).
- Compare a build before and after 78b5a54.
Workaround 🛠️
None needed for typical lists (tens of materialized lines); the cost is probably below noise there.
Works on UWP/WinUI
N/A (Uno's managed ListView panel implementation detail).
Renderer 🎨
Skia
Affected platforms 📱💻🖥️
Skia heads (managed ListView panel). Could be most visible on WASM and low-end Android.
Uno.Sdk version (and other relevant versions) 📦
master 951b7b4 (code inspection)
Anything else we need to know? 💬
Possible fix: keep the deque-end fast path and only fall back to the search when a reorder is active (GetAndUpdateReorderingIndex() is non-null), or cache the extremes and invalidate them on mutation/reorder. GetItemsStart() / GetItemsEnd() could be treated the same way.
Activity