Repository navigation
perf(composition): Drop the CompositionObject finalizer - #25046
MartinZikmund wants to merge 3 commits into
Conversation
|
Claude finished @MartinZikmund's task in 18s —— View job Review of #25046: drop the
|
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25046/wasm-skia-net9/index.html |
|
The build 237636 found UI Test snapshots differences: Details
|
|
|
Disposing a composition object off the UI thread queued StopAllAnimations on the dispatcher even when it had no animations, keeping the object and its subgraph alive until the UI thread drained the queue. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm
Its only job was stopping animations, but a running or paused animation references its target (AnimationFrame handler, Compositor registration, scoped batch, started-objects list), so an unreachable object never has live animations. Native payloads released by DisposeInternal overrides are SkiaSharp objects or backend resources with their own finalizers, and CompositionImageSurface keeps its own. Every visual was finalizable and survived an extra GC for nothing. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm
f399ebc to
ce1c25d
Compare
|
Claude finished @MartinZikmund's task in 15s —— View job Re-review of #25046 after the latest pushVerdict: ship. No new findings and no inline comments. This was a code-review pass only. I did not build or run tests. The diff against the base ( CI: build 237636 failed with 130 Linux and 178 Windows screenshot differences. They are spread across unrelated samples such as Carried over from the earlier review: the thread-safety note on reading |
|
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. |
morning4coffe-dev
left a comment
There was a problem hiding this comment.
Verified at head ce1c25d: read the diff and the surrounding code. All 13 DisposeInternal overrides under src/Uno.UI.Composition call base.DisposeInternal(), directly or after their own cleanup, so the new early return cannot skip subclass cleanup. CompositionImageSurface keeps its own finalizer (CompositionImageSurface.skia.cs, ~CompositionImageSurface), as the PR says. AnimationController holds its target (CompositionObject.cs, TryGetAnimationController returns new(this, ...)), which answers the reachability question raised by the bot review. No public API change; no WinUI parity surface.
Validation: code review only. I did not build, and I did not run the two new runtime tests.
Findings, most severe first:
-
Merge order and the reachability wording (medium). The fix is only safe with #25055 in place, which the PR body states. The invariant in the body is off, though: after #25055, a parked infinite animation holds its host weakly, so "a running or paused animation always keeps its target reachable" is not accurate. The correct reasoning is that an animation whose host is unreachable can no longer be observed or ticked, so skipping
Stop()is harmless. Please reword, and keep the #25055 dependency explicit in the description until it lands. -
Test cleanup (low). In
Given_CompositionObject_Lifetime.cs,DisposeOffThreadcallsGC.SuppressFinalize(visual). With the finalizer gone this is a no-op, and its comment ("Only the explicit Dispose path is under test here") is misleading. Remove both. The comment onCreateDroppedElementVisualsabout short weak references clearing "before the finalizer runs" is also stale. -
Off-thread read (low).
DisposeInternalreads_animations.Countbefore the dispatcher hop, so aDispose()from a non-UI thread races with a UI-threadStartAnimation. The PR does not say whether off-threadDispose()is supported. If it is not, add a comment or an assertion. If it is, the check should move inside the dispatched work.
GitHub Issue: relates to #25042
Important
Stacked on #25055. Dropping the finalizer is only safe once a running animation can no longer outlive its tree, which #25055 fixes. Until both land, #25187 (closes #25042) fixes the retention by suppressing the finalizer while an object has no animations. Once #25187 merges, this PR rebases to remove the finalizer and that suppression logic altogether.
PR Type:
🐞 Bugfix
What changed? 🚀
Every
CompositionObjectwas finalizable, and its finalizer (always off the UI thread) enqueuedStopAllAnimationsonto the UI dispatcher even when there were no animations. Every dead visual was promoted, went through the finalization queue, and stayed alive with its subgraph until the UI thread drained a no-op callback.DisposeInternalreturns early when there are no animations, so nothing is queued.~CompositionObject()finalizer is removed. A running or paused animation always keeps its target reachable (compositor, scoped batch, animation target list), so an unreachable visual never has an animation to stop. EveryDisposeInternaloverride only frees SkiaSharp/drawing objects whose backends have their own finalizers;CompositionImageSurfacekeeps its own finalizer.Measured (Release, net10.0-desktop, 100k
Border { Child = TextBlock }created and dropped while the UI thread is blocked, 3 rounds):Tests:
Given_CompositionObject_Lifetime(2 runtime tests) fail on master and pass with the fix. They use long weak references and collect on a worker thread while the UI thread sleeps, since waiting on the STA UI thread pumps messages and would drain the queue. All 115Windows_UI_Compositionruntime tests pass.Risk: a composition object dropped without
Disposenow frees its Skia handles through SkiaSharp's own finalizers rather thanDisposeInternal: same result, later. No WinUI parity impact (WinUI composition objects are COM objects).PR Checklist ✅
Screenshots Compare Test Runresults.🤖 Generated with Claude Code
https://claude.ai/code/session_01NL1zD4nmcDjrcPhceNXFNm