DryIoc icon indicating copy to clipboard operation
DryIoc copied to clipboard

Add Interpreter intrinsic delegate to execute known method or constructor without reflection

Open dadhi opened this issue 6 years ago • 2 comments
trafficstars

dadhi avatar Aug 12 '19 13:08 dadhi

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.

dadhi avatar Jun 06 '20 10:06 dadhi

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

dadhi avatar Jun 07 '20 09:06 dadhi