* Move MapPathWebRoot & MapPathContentRoot to extension methods. * Set AspNetCoreHostingEnvironment ApplicationId without service provider. * Drop some usages of TempHostingEnvironment * Logging setup cleanup - AppDomainId has no value (it is always "1") Creating new AppDomains isn't possible in .Net core. Attempting to do so results in a platform exception. A dotnet core process has a single AppDomain instance whose Id property is always the integer 1. * Setup logging without IHostingEnvironment * Mark IUmbracoBuilder.BuilderHostingEnvironment obsolete And remove internal usages. * Typeloader no longer uses umbraco-types.list * Added UmbracoHost - setup serilog two-stage init. * Add ApplicationIdEnricher * Defensive tweaks for those not using UmbracoHost * Drop UmbracoHost static class * Setup runtime logger without host builder extensions. * Prevent RefreshingRazorViewEngine related explosions * Filescoped namespaces for new classes. * Apply suggestions from code review
77 lines
2.3 KiB
C#
77 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using BenchmarkDotNet.Attributes;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Umbraco.Cms.Core.Cache;
|
|
using Umbraco.Cms.Core.Composing;
|
|
using Umbraco.Cms.Core.Logging;
|
|
|
|
namespace Umbraco.Tests.Benchmarks
|
|
{
|
|
[MediumRunJob]
|
|
[MemoryDiagnoser]
|
|
public class TypeLoaderBenchmarks
|
|
{
|
|
private readonly TypeLoader _typeLoader1;
|
|
private readonly TypeLoader _typeLoader2;
|
|
|
|
public TypeLoaderBenchmarks()
|
|
{
|
|
var typeFinder1 = new TypeFinder(
|
|
new NullLogger<TypeFinder>(),
|
|
new DefaultUmbracoAssemblyProvider(GetType().Assembly, NullLoggerFactory.Instance));
|
|
|
|
_typeLoader1 = new TypeLoader(typeFinder1, NullLogger<TypeLoader>.Instance);
|
|
_typeLoader2 = new TypeLoader(typeFinder1, NullLogger<TypeLoader>.Instance);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Use a predefined cache of types (names) - this is an example of what is saved to disk and loaded on startup
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
private Dictionary<(string, string), IEnumerable<string>> GetCache()
|
|
=> new Dictionary<(string, string), IEnumerable<string>>
|
|
{
|
|
[(typeof(ITypeLoaderBenchmarkPlugin).FullName, null)] = new List<string>
|
|
{
|
|
typeof(CustomAssemblyProvider1).FullName,
|
|
typeof(CustomAssemblyProvider2).FullName,
|
|
typeof(CustomAssemblyProvider3).FullName
|
|
}
|
|
};
|
|
|
|
[Benchmark(Baseline = true)]
|
|
public void WithTypesCache()
|
|
{
|
|
var found = _typeLoader1.GetTypes<ITypeLoaderBenchmarkPlugin>().Count();
|
|
}
|
|
|
|
[Benchmark]
|
|
public void WithoutTypesCache()
|
|
{
|
|
var found = _typeLoader2.GetTypes<ITypeLoaderBenchmarkPlugin>(false).Count();
|
|
}
|
|
}
|
|
|
|
// These are the types we'll find for the benchmark
|
|
|
|
public interface ITypeLoaderBenchmarkPlugin
|
|
{
|
|
}
|
|
|
|
public class CustomAssemblyProvider1 : ITypeLoaderBenchmarkPlugin
|
|
{
|
|
}
|
|
|
|
public class CustomAssemblyProvider2 : ITypeLoaderBenchmarkPlugin
|
|
{
|
|
}
|
|
|
|
public class CustomAssemblyProvider3 : ITypeLoaderBenchmarkPlugin
|
|
{
|
|
}
|
|
|
|
}
|