Commit fc346491 authored by Savorboard's avatar Savorboard Committed by Lemon

Performance improvements for object creation (#86)

* Add components project of SkyWalking.Diagnostics.EntityFrameworkCore for supports EntityFrameworkCore diagnostics.

* Add builder extensions file and EF diagnostics default impl file.

* Add EntityFrameworkDiagnostic processor.

* Add unit tests for EntityFrameworkCore diagnostics component.

* Fixed parameter bind bug.

* Fast creation of objects using lambda expression instead of Activator.CreateInstance(type) .
parent b231a09a
......@@ -17,6 +17,7 @@
*/
using System;
using System.Linq.Expressions;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using SkyWalking.Config;
......@@ -52,7 +53,7 @@ namespace SkyWalking.Utilities.Configuration
public T Get<T>() where T : class, new()
{
var config = typeof(T).GetCustomAttribute<ConfigAttribute>();
var instance = Activator.CreateInstance<T>();
var instance = New<T>.Instance();
_configuration.GetSection(config.GetSections()).Bind(instance);
return instance;
}
......@@ -62,5 +63,14 @@ namespace SkyWalking.Utilities.Configuration
var config = new ConfigAttribute(sections);
return _configuration.GetSection(config.GetSections()).GetValue<T>(key);
}
//hign performance
private static class New<T> where T : new()
{
public static readonly Func<T> Instance = Expression.Lambda<Func<T>>
(
Expression.New(typeof(T))
).Compile();
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment