Repository: unoplatform/uno
File: src/Uno.UI.Composition/Composition/Visual.skia.cs (C#)

Code before:
				if (visual._picture is not null)
				{
					session.Canvas.DrawPicture(visual._picture);
				}
			}
#if DEBUG
			Debug.Assert(saveCount == session.Canvas.SaveCount);
#endif
		}

		static void PostPaintingClipStep(Visual visual, SKCanvas canvas)
		{
			if (visual.GetPostPaintingClipping() is { } postClip)
			{
				canvas.ClipPath(postClip, antialias: true);
			}
		}

		static void RenderChildrenStep(Visual visual, PaintingSession session, bool applyChildOptimization)
		{
			if (visual._childrenPicture is not null)
			{
				session.Canvas.DrawPicture(visual._childrenPicture);
			}
			else if (!visual._enablePictureCollapsingOptimization
					 || visual._framesSinceSubtreeNotChanged < visual._pictureCollapsingOptimizationFrameThreshold
					 || !applyChildOptimization
					 || visual.GetSubTreeVisualCount() < visual._pictureCollapsingOptimizationVisualCountThreshold)
			{
				foreach (var child in visual.GetChildrenInRenderOrder())
				{
					child.Render(in session, applyChildOptimization);
				}
			}
			else
			{
				var recorder = new SKPictureRecorder();
				var recordingCanvas = recorder.BeginRecording(new SKRect(-999999, -999999, 999999, 999999));
				// child.Render will reapply the total transform matrix, so we need to invert ours.
				Matrix4x4.Invert(visual.TotalMatrix, out var rootTransform);
				_factory.CreateInstance(visual, recordingCanvas, ref rootTransform, session.Opacity, out var childSession);
				using (childSession)
				{
					foreach (var child in visual.GetChildrenInRenderOrder())
					{
						child.Render(in childSession, applyChildOptimization: false);
					}
				}

				var picture = recorder.EndRecording();
				session.Canvas.DrawPicture(picture);

Review comment (bug):
All methods on `Debug` class are conditional to `DEBUG`, no needs to add it again

```suggestion
			Debug.Assert(nonOptimizedClip.IsClipRect == canvas.IsClipRect && nonOptimizedClip.DeviceClipBounds == canvas.DeviceClipBounds);
```

Code after:
				if (visual._picture is not null)
				{
					session.Canvas.DrawPicture(visual._picture);
				}
			}
#if DEBUG
			Debug.Assert(saveCount == session.Canvas.SaveCount);
#endif
		}

		static void PostPaintingClipStep(Visual visual, SKCanvas canvas)
		{
#if DEBUG
			canvas.Save();
			if (visual.GetPostPaintingClipping() is { } postClip)
			{
				canvas.ClipPath(postClip, antialias: true);
			}

			var nonOptimizedClip = (canvas.DeviceClipBounds, canvas.IsClipRect);
			canvas.Restore();
#endif
			visual.ApplyPostPaintingClipping(canvas);
#if DEBUG
			Debug.Assert(nonOptimizedClip.IsClipRect == canvas.IsClipRect && nonOptimizedClip.DeviceClipBounds == canvas.DeviceClipBounds);
#endif
		}

		static void RenderChildrenStep(Visual visual, PaintingSession session, bool applyChildOptimization)
		{
			if (visual._childrenPicture is not null)
			{
				session.Canvas.DrawPicture(visual._childrenPicture);
			}
			else if (!visual._enablePictureCollapsingOptimization
					 || visual._framesSinceSubtreeNotChanged < visual._pictureCollapsingOptimizationFrameThreshold
					 || !applyChildOptimization
					 || visual.GetSubTreeVisualCount() < visual._pictureCollapsingOptimizationVisualCountThreshold)
			{
				foreach (var child in visual.GetChildrenInRenderOrder())
				{
					child.Render(in session, applyChildOptimization);
				}
			}
			else
			{
				var recorder = new SKPictureRecorder();
				var recordingCanvas = recorder.BeginRecording(new SKRect(-999999, -999999, 999999, 999999));
				// child.Render will reapply the total transform matrix, so we need to invert ours.
				Matrix4x4.Invert(visual.TotalMatrix, out var rootTransform);
				_factory.CreateInstance(visual, recordingCanvas, ref rootTransform, session.Opacity, out var childSession);