Repository navigation
perf(grid): Stop leaking the pooled span store on the empty path - #24229
Conversation
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a performance bug in Grid.MeasureCellsGroup where an ArrayPool<T>-rented backing array (via SpanStoreStackVector) could be leaked on the empty-group early-return path, causing pool bucket drain and downstream allocations during repeated grid measure passes.
Changes:
- Moves
SpanStoreStackVectorconstruction to occur after thecellsHead >= cellCountearly return, preventing pool rentals on the empty path. - Adds a clarifying comment explaining why the construction must not precede an exit path.
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24229/wasm-skia-net9/index.html |
|
The build 230527 found UI Test snapshots differences: Details
|
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
375f343 to
f3f33bc
Compare
|
Claude encountered an error after 0s —— View job I'll analyze this and get back to you. |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24229/wasm-skia-net9/index.html |
|
The build 231007 found UI Test snapshots differences: Details
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-24229/wasm-skia-net9/index.html |
|
The build 231679 found UI Test snapshots differences: Details
|
|
This pull request does not currently match the merge queue conditions, so it cannot be queued from here. The box comes back if it matches again. |
|
@Mergifyio backport servicing/6.8 release/stable/6.7 |
✅ Backports have been createdDetails
|
…r-24229 perf(grid): Stop leaking the pooled span store on the empty path (backport #24229)
…6.7/pr-24229 perf(grid): Stop leaking the pooled span store on the empty path (backport #24229)
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 run