Repository navigation
perf(composition): Suppress the finalizer without animations - #25187
Conversation
Every CompositionObject was finalizable, and its finalizer queued a no-op StopAllAnimations onto the UI thread, retaining every dead visual and its subgraph until the UI thread drained it. Suppress finalization while an object has no animations and re-register it when the first one starts, and skip queuing the stop when there is nothing to stop. CompositionImageSurface keeps its own finalizer. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYKir5hPkrgan2z9NajHM7
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KYKir5hPkrgan2z9NajHM7
|
Claude finished @MartinZikmund's task in 18s —— View job Review of #25187: suppress the CompositionObject finalizer without animationsVerdict: ship. I found no blocking issues. This is a code review only; I did not build or run anything. Issues by severity: 0 blocking, 0 major, 2 minor notes (below). I posted no inline comments. What I checked
Minor notes (non-blocking)
Cross-cutting: this is explicitly an interim safety net until #25055 lets a running animation no longer outlive its tree. It would help to track removing |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25187/wasm-skia-net9/index.html |
|
The build 238801 found UI Test snapshots differences: Details
|
|
|
Browser WASM has no thread to run the Task.Run work while the UI thread spins, so the run hung on these tests. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TP1JtY64etkfxxGCms44aN
|
Claude finished @MartinZikmund's task in 15s —— View job Review of #25187: suppress the CompositionObject finalizer without animationsVerdict: ship. I found no blocking issues. This was a code review only. I did not build or run anything. Issues by severity: 0 blocking, 0 major, 2 minor. I posted no inline comments. What I checked
Minor notes (non-blocking)
CI: build 238801 failed. The screenshot diffs are broad (2458 of 2486 on Windows) and span unrelated samples such as Cross-cutting: this is an interim safety net until #25055 lands. It would help to track removing |
|
🤖 Your WebAssembly Skia Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-25187/wasm-skia-net9/index.html |
GitHub Issue: closes #25042
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.This is the conservative alternative to #25046, which drops the finalizer entirely. Dropping it is only safe once a running animation can no longer outlive its tree (#25055), so #25046 is now stacked on #25055 and this PR keeps the finalizer as a safety net in the meantime:
GC.SuppressFinalizein the constructor and when the last animation stops) and re-registered when the first animation starts (GC.ReRegisterForFinalize). The toggle only fires on a state change, since re-registering an already registered object queues its finalizer twice.DisposeInternalreturns early when there are no animations, so an explicit off-threadDisposequeues nothing either.CompositionImageSurfacehas its own finalizer, which a base-classSuppressFinalizewould silently disable, so it opts out (HasOwnFinalizer).Measured (Release, net10.0-desktop, 100k
Border { Child = TextBlock }created and dropped while the UI thread is blocked, 3 rounds, same machine and harness):The remaining gap to #25046 is the cost of allocating finalizable objects plus the
SuppressFinalizecall; the retention, which is the real problem, is gone.Tests:
Given_CompositionObject_Lifetime(Skia runtime tests, long weak references, collecting on a worker thread while the UI thread sleeps so nothing drains the queue):When_Elements_Dropped_Then_Visuals_Collected_Without_Dispatcher,When_Visual_Disposed_Off_Thread_Then_Nothing_Queued(from perf(composition): Drop the CompositionObject finalizer #25046) andWhen_Animation_Stopped_Then_Visual_Collected_Without_Dispatcher: fail on master, pass with the fix.When_Animated_Visual_Dropped_Then_Finalizer_Stops_Animation: passes on both; guards that a visual dropped with a running animation is still finalized and released once the UI thread stops it (it fails with perf(composition): Drop the CompositionObject finalizer #25046's approach).Regression:
Windows_UI_Composition,Given_AnimatedVisualPlayer,Given_ProgressRing,Given_Storyboard,Given_AnimatedIconruntime tests on Skia Desktop: 150/150 pass.Risk: a composition object without animations dropped without
Disposefrees 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_01KYKir5hPkrgan2z9NajHM7