Skip to content

Grid.MeasureCellsGroup leaks its pooled span-store array on the empty-group path #24220

Closed

Description

@MartinZikmund

Current behavior 🐛

SpanStoreStackVector derives from StackVector<T>, which rents from ArrayPool<T>.Shared in its constructor (src/Uno.WinRT/Collections/StackVector.cs) and returns the array in Dispose(). Grid.MeasureCellsGroup constructs it before its early return, so that path skips the Dispose() at the end of the method and the rented array is never given back:

SpanStoreStackVector spanStore = new SpanStoreStackVector();

if (cellsHead >= cellCount)
{
    return;              // <-- never reaches spanStore.Dispose() at the end of the method
}

Grid.MeasureOverride calls MeasureCellsGroup up to seven times per measure, once per cell group, and a group head is int.MaxValue when the group is empty — so a typical grid takes the leaking path two to three times per measure while returning only one array. The pool bucket drains, after which every Rent allocates a fresh array.

Expected behavior 🎯

The rented array is returned on every path.

How to reproduce it (as minimally and precisely as possible) 🔬

Measure managed allocations across repeated dirty layout passes of a grid-heavy tree (341 Grids with Auto rows and * columns, 1,365 elements).

Measured impact 📊

Workload Metric Before After Δ
grid.full-pass alloc / pass 390,105 B 79,113 B −79.7 %
grid.full-pass alloc / element 285.8 B 58.0 B −79.7 %
grid.full-pass time / pass 3.67 ms 3.11 ms −15.3 %

Isolated by reverting and re-applying this change alone on the current tree, both runs executing the workload alone. Allocation figures are byte-identical across runs. The saving is exactly the leaked rentals: ~3 per grid per pass × 341 grids × a 16-element SpanStoreEntry[].

Workaround 🛠️

None available from application code.

Renderer 🎨

  • Skia

Affected platforms 📱💻🖥️

All platforms 🌍

Uno.Sdk version (and other relevant versions) 📦

Present in current development branches.

Anything else we need to know? 💬

Found by allocation profiling — dotnet-trace attributed by type and call stack — and measured before/after with the same harness. Full evidence: specs/059-performance-improvements/evidence.md.

Activity

  1. added
    triage/untriaged
    on Aug 27, 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

    triage/untriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions