From 1fcabca32809d3a33a204eb1978e00ceefa2fbac Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 6 Mar 2025 13:51:31 +0000 Subject: [PATCH] add a benchmark for inherited property change notifications. --- .../Data/InheritedProperties.cs | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Avalonia.Benchmarks/Data/InheritedProperties.cs diff --git a/tests/Avalonia.Benchmarks/Data/InheritedProperties.cs b/tests/Avalonia.Benchmarks/Data/InheritedProperties.cs new file mode 100644 index 0000000000..2579a228c9 --- /dev/null +++ b/tests/Avalonia.Benchmarks/Data/InheritedProperties.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using Avalonia.Controls; +using Avalonia.UnitTests; +using BenchmarkDotNet.Attributes; + +namespace Avalonia.Benchmarks.Data; + +[MemoryDiagnoser] +public class InheritedProperties +{ + private readonly TestRoot _root; + private readonly List _controls = new(); + + public InheritedProperties() + { + var panel = new StackPanel(); + + _root = new TestRoot + { + Child = panel, + Renderer = new NullRenderer() + }; + + _controls.Add(panel); + _controls = ControlHierarchyCreator.CreateChildren(_controls, panel, 3, 5, 5); + + _root.LayoutManager.ExecuteInitialLayoutPass(); + } + + [Benchmark, MethodImpl(MethodImplOptions.NoInlining)] + public void ChangeDataContext() + { + TestDataContext[] dataContexts = [new(), new(), new()]; + + for (int i = 0; i < 100; i++) + { + for (int j = 0; j < dataContexts.Length; j++) + { + _root.DataContext = dataContexts[j]; + } + } + } + + public class TestDataContext; +}