Skip to content

fix(composition): Prune dead context entries on add (backport #26124) - #26152

Merged
Xiaoy312 merged 6 commits into
servicing/6.8from
mergify/bp/servicing/6.8/pr-26124
Nov 8, 2026
Merged

Xiaoy312 merged 6 commits into
servicing/6.8from
mergify/bp/servicing/6.8/pr-26124

Conversation

@mergify

@mergify mergify Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

GitHub Issue: closes unoplatform/kahua-private#569

PR Type:

🐞 Bugfix

What changed? 🚀

A composition brush keeps a weak "context" entry (a WeakReference and its GC handle) for every visual or shape that uses it, so it can propagate its changes. A consumer only removes its entry when its brush property is reassigned. Consumers that are simply unloaded and collected left their entry on the brush, and only a change of the brush pruned them. Shared theme/resource brushes rarely change, so their list grew without bound: 3 entries per Border + Rectangle that ever used the brush.

CompositionObject.AddContext now sweeps dead entries once the list reaches a threshold, then resets the threshold to twice the surviving count (minimum 16). The sweep is skipped while PropagateChanged walks the same list.

  • Bounded, not eagerly reclaimed: dead entries stay until the next add or change of that brush, at most about twice the peak number of live consumers.
  • Why the brush sweeps, and not the consumer: composition objects suppress finalization, and a weak reference is cleared before finalizers run, so a collected consumer can't remove its own entry. Only the list owner can see it died. WinUI has no equivalent list; native composition releases references deterministically.
  • Tests: 3 Skia runtime tests in Given_CompositionObject_Context. They fail without the fix (1000 / 1050 / 303 entries) and pass with it. The expected counts include any consumers the GC failed to collect (conservative stack scanning on WASM / mobile), and a test fails visibly if more than 10% stay alive. The XAML test also checks that the live Border and Rectangle still render a brush change after the sweep.
  • Manual sample: CompositionBrushContextLeak in SamplesApp.

The fix commit is the reporter's patch, kept verbatim; follow-ups are separate commits.

PR Checklist ✅

🤖 Generated with Claude Code


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

jbourque-kahua and others added 3 commits November 6, 2026 17:34
CompositionObject.AddContext appended a weak ContextEntry per consumer but never swept dead ones. A consumer (BorderVisual, CompositionSpriteShape, SpriteVisual) only removes its entry when its brush property is reassigned, so consumers that are simply collected left their entry on the brush. Shared theme/resource brushes rarely raise changes (PropagateChanged is the only other place that prunes), so their list and its WeakReference GC handles grew without bound (3 entries per Border+Rectangle using the brush).

AddContext now sweeps dead entries once the list reaches a threshold, then resets the threshold to twice the surviving count (min 16): O(live consumers) size, amortized O(1) per add. The sweep is skipped while PropagateChanged is iterating the same list.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 4875228)
Conservative GC (WASM, mobile) can keep a consumer alive, which then
legitimately keeps its entry. Derive the expected counts from the
measured survivors instead of assuming every consumer was collected,
and fail visibly if most of them were not.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 95ee120)
@mergify mergify Bot added the conflicts Automated merge hit conflicts label Nov 6, 2026
@mergify

mergify Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor Author

Cherry-pick of b393072 has failed:

On branch mergify/bp/servicing/6.8/pr-26124
Your branch is ahead of 'origin/servicing/6.8' by 3 commits.
  (use "git push" to publish your local commits)

You are currently cherry-picking commit b393072.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   specs/lessons.md

no changes added to commit (use "git add" and/or "git commit -a")

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@github-actions github-actions Bot added area/automation Categorizes an issue or PR as relevant to project automation kind/documentation labels Nov 6, 2026
Xiaoy312 and others added 3 commits November 6, 2026 12:43
Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 22504e2)
The XAML leak test now asserts the live Border and Rectangle keep
their entries and still render a brush change after the sweep, and
resets the window content.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
(cherry picked from commit e94e47e)
6.x still keeps composition tests under Tests/Windows_UI_Composition
and samples under Windows_UI_Composition.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Xiaoy312
Xiaoy312 force-pushed the mergify/bp/servicing/6.8/pr-26124 branch from 9bbffdf to 34809d2 Compare November 6, 2026 17:47
@Xiaoy312 Xiaoy312 removed the conflicts Automated merge hit conflicts label Nov 6, 2026
@unodevops

Copy link
Copy Markdown
Contributor

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

@mergify

mergify Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

@Xiaoy312
Xiaoy312 merged commit 435adcf into servicing/6.8 Nov 8, 2026
42 checks passed
@Xiaoy312
Xiaoy312 deleted the mergify/bp/servicing/6.8/pr-26124 branch November 8, 2026 03:14
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 kind/documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants