Browse Source
* Add an optimized path for notifying property changes for inherited values Avoids many allocations of event args. * fix unit tests with hack to prove concept. * update docs and remove value tuple that could cause allocation. * add a benchmark for inherited property change notifications.pull/18558/head
committed by
GitHub
4 changed files with 94 additions and 22 deletions
@ -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<Control> _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; |
||||
|
} |
||||
Loading…
Reference in new issue