Skip to content

Commit

Permalink
feat(perf): Fix lazy creation of ShapeCollection when not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Aug 7, 2023
1 parent 7ff9e1e commit fbf1e7a
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions src/Uno.UI.Composition/Composition/ShapeVisual.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
#nullable enable

namespace Windows.UI.Composition
namespace Windows.UI.Composition;

public partial class ShapeVisual : ContainerVisual
{
public partial class ShapeVisual : ContainerVisual
private CompositionViewBox? _viewBox;
private CompositionShapeCollection? _shapes;

public ShapeVisual(Compositor compositor)
: base(compositor)
{
private CompositionViewBox? _viewBox;
private CompositionShapeCollection? _shapes;
}

public ShapeVisual(Compositor compositor)
: base(compositor)
{
// Add this as context for the shape collection so we get
// notified about changes in the shapes object graph.
OnCompositionPropertyChanged(null, Shapes, nameof(Shapes));
}
public CompositionViewBox? ViewBox
{
get => _viewBox;
set => SetProperty(ref _viewBox, value);
}

public CompositionViewBox? ViewBox
// This is lazy as we are using the `ShapeVisual` for UIElement, but lot of them are not creating shapes, reduce memory pressure.
public CompositionShapeCollection Shapes
{
get
{
get => _viewBox;
set => SetProperty(ref _viewBox, value);
}
if (_shapes is null)
{
_shapes = new CompositionShapeCollection(Compositor, this);

// This ia lazy as we are using the `ShapeVisual` for UIElement, but lot of them are not creating shapes, reduce memory pressure.
public CompositionShapeCollection Shapes => _shapes ??= new CompositionShapeCollection(Compositor, this);
// Add this as context for the shape collection so we get
// notified about changes in the shapes object graph.
OnCompositionPropertyChanged(null, _shapes, nameof(Shapes));
}

return _shapes;
}
}
}

0 comments on commit fbf1e7a

Please sign in to comment.