Skip to content

perf(grid): Stop leaking the pooled span store on the empty path (backport #24229) - #25752

Merged
agneszitte merged 1 commit into
servicing/6.8from
mergify/bp/servicing/6.8/pr-24229
Oct 27, 2026
Merged

agneszitte merged 1 commit into
servicing/6.8from
mergify/bp/servicing/6.8/pr-24229

Conversation

@mergify

@mergify mergify Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes #24220

PR Type:

🐞 Bugfix

What changed? 🚀

SpanStoreStackVector rents from ArrayPool<T>.Shared in its constructor and returns the array in Dispose(). MeasureCellsGroup constructed it before the cellsHead >= cellCount early return, so that path never gave the array back. Grid.MeasureOverride calls MeasureCellsGroup up to seven times per measure and empty groups are the common case, so a typical grid leaked two to three rentals per measure while returning one: the pool bucket drains and every subsequent rent allocates.

Move the early return above the construction — nothing touches the vector before that point, so the change is inert other than not renting.

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.

Validation ✅

Runtime tests, Skia Desktop, Given_Grid + Given_GridLayouting + Given_GridView_Items: 85 run, 81 passed, 4 skipped, 4 failed. All 4 failures reproduce on the baseline and on the tree before any of this work, verified by two separate rebuild-and-rerun cycles.

PR Checklist ✅

  • 🧪 Added Runtime tests, UI tests, or a manual test sample (for bug fixes / features, if applicable)
  • 📚 Docs have been added/updated following the documentation template (for bug fixes / features) — n/a, no API or behaviour change for app authors
  • 🖼️ Validated PR Screenshots Compare Test Run results. — to check once CI has run
  • ❗ Contains NO breaking changes
  • 👀 Reviewed 2 other open pull requests (optional but appreciated!)

This is an automatic backport of pull request #24229 done by [Mergify](https://mergify.com).

SpanStoreStackVector rents from ArrayPool<T>.Shared in its constructor
and returns the array in Dispose(). MeasureCellsGroup constructed it
before the cellsHead >= cellCount early return, so that path never gave
the array back. Grid.MeasureOverride calls MeasureCellsGroup up to seven
times per measure and empty groups are the common case, so a typical
grid leaked two to three rentals per measure while returning one: the
pool bucket drains and every subsequent rent allocates.

Move the early return above the construction; nothing touches the vector
before that point.

Measured on a 341-Grid tree (specs/059-performance-improvements): a full
dirty layout pass drops from 3.73 ms to 1.32 ms (-65%) and from 431 KB to
120 KB of allocations (-72%). The 311 KB saved is ~1023 leaked rentals of
a 16-element SpanStoreEntry[], matching the leak one for one.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_015DSdL5YzLhjx8CeGXZf1Au
(cherry picked from commit f3f33bc)
@agneszitte
agneszitte merged commit 79f189f into servicing/6.8 Oct 27, 2026
12 of 20 checks passed
@agneszitte
agneszitte deleted the mergify/bp/servicing/6.8/pr-24229 branch October 27, 2026 21:42
@unodevops

Copy link
Copy Markdown
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants