Repository navigation
perf(grid): Stop leaking the pooled span store on the empty path (backport #24229) - #25752
Merged
Merged
Conversation
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)
1 of 5 tasks
agneszitte
approved these changes
Oct 27, 2026
Contributor
|
🤖 Your WebAssembly Sample App stage site is ready! Visit it here: |
Merged
1 task done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GitHub Issue: closes #24220
PR Type:
🐞 Bugfix
What changed? 🚀
SpanStoreStackVectorrents fromArrayPool<T>.Sharedin its constructor and returns the array inDispose().MeasureCellsGroupconstructed it before thecellsHead >= cellCountearly return, so that path never gave the array back.Grid.MeasureOverridecallsMeasureCellsGroupup 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 📊
grid.full-passgrid.full-passgrid.full-passIsolated 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 ✅
Screenshots Compare Test Runresults. — to check once CI has runThis is an automatic backport of pull request #24229 done by [Mergify](https://mergify.com).