Skip to content

ListView managed panel: materialized first/last accessors are linear scans called inside the fill loops #25294

Open

Description

@MartinZikmund

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,
    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,
    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: evaluates GetItemsStart() and GetFirstMaterializedIndexPath() every iteration,
    void FillBackward()
    {
    while (
    GetItemsStart() is { } start && start > ExtendedViewportStart + extentAdjustment &&
    GetNextUnmaterializedItem(Backward, GetFirstMaterializedIndexPath()) is { } nextItem)
    {
    AddLine(Backward, nextItem);
    }
    }
  • FillForward: evaluates GetItemsEnd() and GetLastMaterializedIndexPath() every iteration, same file L555-L565
  • AddLine also calls GetContentStart() / 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:

  1. Create a Skia app with a ListView using small fixed-height items (e.g. 10px Borders) in a tall viewport, so several hundred lines are materialized.
  2. Scroll in small steps, measuring UI-thread time per scroll step (or count calls to the four accessors per fill pass).
  3. 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

  1. added
    kind/bug
    triage/untriaged
    area/skia ✏️
    area/listview 📃
    project/items 🧾
    difficulty/medium 🤔
    area/performance 📈
    7.1
    on Oct 11, 2026
  2. removed
    7.1
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/listview 📃area/performance 📈area/skia ✏️difficulty/medium 🤔kind/bugproject/items 🧾triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions