Skip to content

fix: Don't let the DP storage pools keep arrays of collected objects (6.8) - #26220

Merged
agneszitte merged 3 commits into
servicing/6.8from
dev/xygu/20261107/dp-pool-retention-6.8
Nov 9, 2026
Merged

agneszitte merged 3 commits into
servicing/6.8from
dev/xygu/20261107/dp-pool-retention-6.8

Conversation

@Xiaoy312

@Xiaoy312 Xiaoy312 commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Note

Servicing-only change: there is no master PR to backport. 7.0 already fixes this differently. #23703 removed the DependencyObject finalizer, and #25047 replaced the pooled property storage with arrays allocated directly. Both depend on the 7.0 DependencyObject refactor, so they aren't suitable for servicing.

The 6.7 version (the same 3 commits, which apply cleanly to release/stable/6.7) is on hold until the related 6.7 PRs are merged.

GitHub Issue: closes unoplatform/kahua-private#571

PR Type:

🐞 Bugfix

What changed? 🚀

On 6.x, each DependencyObject keeps its property values in a DependencyPropertyDetailsCollection, with two arrays rented from static pools: the DependencyPropertyDetails?[] entries (LinearArrayPool) and the short[] offsets (ArrayPool<short>.Shared). Those pools keep up to 8192 arrays per bucket and trim slowly.

Arrays of collected objects filled the pools (04197b6)

  • Dispose returned both arrays to the pools. On Skia it runs from the DependencyObjectStore finalizer, so after each GC the arrays of every collected object went back to the pools at once, while the live UI kept its own.
  • As a result, the pools held as many arrays as the largest single GC had ever collected, for the life of the process. The reporter measured about 6 MB of pooled arrays after opening and closing a view 20 times, with a flat count of live objects.
  • Dispose now leaves the final arrays to the GC, as 7.0 does. Arrays released while a collection grows are still returned to the pools, so the resize path keeps its reuse.
  • Trade-off: the final arrays are no longer reused. The issue measured about +8% allocated per Border and +13% per ColumnDefinition. perf: Size DependencyProperty storage to the properties set #25047 reports a similar cost on master.

The offsets array was rented 16x too large (cae558c)

This is a cherry-pick of fbfead433f from master, unchanged. _entryOffsets is indexed by bucket index alone, but it rented (bucketIndex * 16) + 1 slots instead of bucketIndex + 1.

Tests (Given_DependencyPropertyDetailsCollection, unit tests)

  • When_DependencyObjects_Collected_Then_Storage_Arrays_Collected: without the fix, all 200 arrays of 100 collected ColumnDefinitions outlive them, because the pools hold them.
  • When_Store_Disposed_Then_Storage_Arrays_Not_Returned_To_Pools: covers an explicit Dispose of the store, which iOS/macOS native views use.
  • When_Property_In_High_Bucket_Then_Offsets_Sized_To_Bucket_Index: without the cherry-pick, it fails with 256 offsets rented for bucket index 12.

The tests keep weak references to the object's own arrays, so they don't depend on what else is in the pools. These weak references track resurrection: plain ones are cleared before the store's finalizer hands the arrays to the pools.

master has a Given_DependencyPropertyDetailsCollection.cs with different tests (for the 7.0 table). Should 6.x ever be merged into master, keep master's version.

Validation

  • Unit tests (Uno.UI.UnitTests, net10.0, Windows):
    • The 3 new tests fail without the fixes and pass with them.
    • Given_DependencyObject*, Given_DependencyProperty*, Buffers and Binder: 278 passed, 0 failed, 3 skipped.
  • Runtime tests, WASM and mobile: covered by CI only.

PR Checklist ✅

🤖 Generated with Claude Code

MartinZikmund and others added 3 commits November 8, 2026 12:45
_entryOffsets is indexed by bucketIndex alone, so it needs bucketIndex + 1
slots, but it rented (bucketIndex * BucketSize) + 1 - a 16x over-allocation.
Because bucketIndex derives from DependencyProperty.UniqueId, a process-wide
counter, the waste scales with the highest property id an object touches: with
~2000 properties registered in Uno.UI alone, a DependencyObject that sets a
late-registered property carried a 4 KB short[] where 256 bytes suffice.

The multiplier bought nothing. ArrayPool rounds a request up to a power-of-two
bucket, so growth stays geometric and resizes stay amortized O(1); the total
allocated across resizes is now ~2x the final size rather than one 16x slab.
The oversized InitBlockUnaligned fill shrinks with it.

Measured at bucket index 17: 512 slots rented for 18 needed, now 32.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016yv4DH5RYAoVM8GjEWtXDS
(cherry picked from commit fbfead4)
DependencyPropertyDetailsCollection.Dispose returned its entries and offsets
arrays to static pools that keep up to 8192 arrays per bucket. Dispose mostly
runs from the DependencyObjectStore finalizer, so after each GC the arrays of
every collected DependencyObject went back to the pools at once, while the live
UI kept its own. The pools ended up holding the largest number of objects any
single GC collected, for the life of the process.

Leave the final arrays to the GC instead, as 7.0 does (its storage no longer
uses pools). Arrays released while a collection grows are still pooled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the area/automation Categorizes an issue or PR as relevant to project automation label Nov 8, 2026
@mergify

mergify Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

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.

@agneszitte
agneszitte merged commit 8be1701 into servicing/6.8 Nov 9, 2026
42 checks passed
@agneszitte
agneszitte deleted the dev/xygu/20261107/dp-pool-retention-6.8 branch November 9, 2026 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/automation Categorizes an issue or PR as relevant to project automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants