DryIoc
DryIoc copied to clipboard
Add Interpreter intrinsic delegate to execute known method or constructor without reflection
It should be possible to call the RegisteredDelegate already.. presumably.
c.RegisterDelegate<A, B, C>((a, b) => new C(a, b));
The problem that we are losing the static types information here. We may create a Func<object[], object>, so that p => func((A)p[0], (B)p[1]).
Then we may store this function in registration to use later for Interpretation.
But we need to compare the performance of Reflection Invoke against call of nested func with converted arguments.
Here is the results:
BenchmarkDotNet=v0.12.0, OS=Windows 10.0.18363
Intel Core i7-8750H CPU 2.20GHz (Coffee Lake), 1 CPU, 12 logical and 6 physical cores
.NET Core SDK=3.1.202
[Host] : .NET Core 3.1.4 (CoreCLR 4.700.20.20201, CoreFX 4.700.20.22101), X64 RyuJIT
DefaultJob : .NET Core 3.1.4 (CoreCLR 4.700.20.20201, CoreFX 4.700.20.22101), X64 RyuJIT
| Method | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Gen 2 | Allocated |
|-------------------- |----------:|---------:|---------:|------:|-------:|------:|------:|----------:|
| ReflectionInvoke | 159.67 ns | 0.684 ns | 0.640 ns | 1.00 | 0.0236 | - | - | 112 B |
| CallObjectParamFunc | 16.48 ns | 0.129 ns | 0.115 ns | 0.10 | 0.0153 | - | - | 72 B |
Source https://github.com/dadhi/FastExpressionCompiler/blob/v3-dev/test/FastExpressionCompiler.Benchmarks/ReflectionInvoke_vs_CallWithObjectArgsAndNestedLambda.cs