generated from nventive/Template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from nventive/dev/jpl/benchmarks
Benchmarks and LoggerMessage optimizations
- Loading branch information
Showing
32 changed files
with
416 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/DynamicMvvm.Abstractions/LoggerMessages.Abstractions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Chinook.DynamicMvvm | ||
{ | ||
internal static partial class LoggerMessagesAbstractions | ||
{ | ||
[LoggerMessage(101, LogLevel.Warning, "Resolving property '{ViewModelTypeName}.{PropertyName}' using reflection on '{ViewModelName}'.")] | ||
public static partial void LogViewModelResolvingPropertyUsingReflection(this ILogger logger, string viewModelTypeName, string propertyName, string viewModelName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using BenchmarkDotNet.Attributes; | ||
using Chinook.DynamicMvvm; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace DynamicMvvm.Benchmarks; | ||
|
||
[MemoryDiagnoser] | ||
public class Benchmark | ||
{ | ||
private readonly IServiceProvider _serviceProvider = new HostBuilder() | ||
.ConfigureServices(serviceCollection => serviceCollection | ||
.AddSingleton<IDynamicCommandBuilderFactory, DynamicCommandBuilderFactory>() | ||
.AddSingleton<IDynamicPropertyFactory, DynamicPropertyFactory>() | ||
) | ||
.Build() | ||
.Services; | ||
|
||
private ViewModel? _viewModel1; | ||
private ViewModel? _viewModel2; | ||
|
||
[Benchmark] | ||
public void CreateViewModel() | ||
{ | ||
var vm = new ViewModel(_serviceProvider); | ||
} | ||
|
||
[Benchmark] | ||
public void CreateViewModel_WithExplicitName() | ||
{ | ||
var vm = new ViewModel("ViewModel", _serviceProvider); | ||
} | ||
|
||
[IterationSetup(Targets = new[] | ||
{ | ||
nameof(ReadProperty_Unresolved), | ||
nameof(ReadProperty_Resolved), | ||
nameof(SetProperty_Unresolved), | ||
nameof(SetProperty_Resolved), | ||
nameof(DisposeViewModel), | ||
})] | ||
public void SetupViewModel() | ||
{ | ||
_viewModel1 = new ViewModel("ViewModel", _serviceProvider); | ||
} | ||
|
||
[IterationSetup(Targets = new[] | ||
{ | ||
nameof(SetProperty_Unresolved_WithListener), | ||
nameof(SetProperty_Resolved_WithListener), | ||
nameof(DisposeViewModel_WithListener), | ||
})] | ||
public void SetupViewModelWithListener() | ||
{ | ||
_viewModel2 = new ViewModel("ViewModel", _serviceProvider); | ||
_viewModel2.PropertyChanged += (s, e) => { }; | ||
} | ||
|
||
[Benchmark] | ||
public void ReadProperty_Unresolved() | ||
{ | ||
var value = _viewModel1!.Number; | ||
} | ||
|
||
[Benchmark] | ||
public void ReadProperty_Resolved() | ||
{ | ||
var value = _viewModel1!.NumberResolved; | ||
} | ||
|
||
[Benchmark] | ||
public void SetProperty_Unresolved() | ||
{ | ||
_viewModel1!.Number = 1; | ||
} | ||
|
||
[Benchmark] | ||
public void SetProperty_Resolved() | ||
{ | ||
_viewModel1!.NumberResolved = 1; | ||
} | ||
|
||
[Benchmark] | ||
public void DisposeViewModel() | ||
{ | ||
_viewModel1!.Dispose(); | ||
} | ||
|
||
[Benchmark] | ||
public void SetProperty_Unresolved_WithListener() | ||
{ | ||
_viewModel2!.Number = 1; | ||
} | ||
|
||
[Benchmark] | ||
public void SetProperty_Resolved_WithListener() | ||
{ | ||
_viewModel2!.NumberResolved = 1; | ||
} | ||
|
||
[Benchmark] | ||
public void DisposeViewModel_WithListener() | ||
{ | ||
_viewModel2!.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="BenchmarkDotNet" Version="0.13.11" /> | ||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\DynamicMvvm.CollectionTracking\DynamicMvvm.CollectionTracking.csproj" /> | ||
<ProjectReference Include="..\DynamicMvvm.FluentValidation\DynamicMvvm.FluentValidation.csproj" /> | ||
<ProjectReference Include="..\DynamicMvvm.Reactive\DynamicMvvm.Reactive.csproj" /> | ||
<ProjectReference Include="..\DynamicMvvm\DynamicMvvm.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using BenchmarkDotNet.Running; | ||
using DynamicMvvm.Benchmarks; | ||
using Chinook.DynamicMvvm; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
BenchmarkRunner.Run<Benchmark>(); | ||
|
||
// The following section is to profile manually using Visual Studio's debugger. | ||
|
||
//var serviceProvider = new HostBuilder() | ||
// .ConfigureServices(serviceCollection => serviceCollection | ||
// .AddSingleton<IDynamicCommandBuilderFactory, DynamicCommandBuilderFactory>() | ||
// .AddSingleton<IDynamicPropertyFactory, DynamicPropertyFactory>() | ||
// ) | ||
// .Build() | ||
// .Services; | ||
|
||
//var vm1 = new ViewModel("ViewModel", serviceProvider); | ||
//var vm2 = new ViewModel("ViewModel", serviceProvider); | ||
|
||
//Console.Read(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Chinook.DynamicMvvm; | ||
|
||
namespace DynamicMvvm.Benchmarks; | ||
|
||
public class ViewModel : ViewModelBase | ||
{ | ||
public ViewModel(string? name, IServiceProvider serviceProvider) | ||
: base(name, serviceProvider) | ||
{ | ||
var value = NumberResolved; | ||
} | ||
|
||
public ViewModel(IServiceProvider serviceProvider) | ||
: this(name: default, serviceProvider: serviceProvider) | ||
{ | ||
} | ||
|
||
public int Number | ||
{ | ||
get => this.Get(initialValue: 42); | ||
set => this.Set(value); | ||
} | ||
|
||
public int NumberResolved | ||
{ | ||
get => this.Get(initialValue: 42); | ||
set => this.Set(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/DynamicMvvm.FluentValidation/LoggerMessages.FluentValidation.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Chinook.DynamicMvvm | ||
{ | ||
internal static partial class LoggerMessages | ||
{ | ||
[LoggerMessage(201, LogLevel.Error, "Validation failed for property '{PropertyName}'.")] | ||
public static partial void LogValidationFailed(this ILogger logger, string propertyName, Exception exception); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Chinook.DynamicMvvm | ||
{ | ||
internal static partial class LoggerMessagesReactive | ||
{ | ||
[LoggerMessage(301, LogLevel.Debug, "Deactivated observable of type '{TypeName}'.")] | ||
public static partial void LogDeactivatedObservable(this ILogger logger, string typeName); | ||
|
||
[LoggerMessage(302, LogLevel.Debug, "Reactivated observable of type '{TypeName}'.")] | ||
public static partial void LogReactivatedObservable(this ILogger logger, string typeName); | ||
|
||
} | ||
} |
Oops, something went wrong.