seesharper / ProxyBenchmarks

.Net dynamic proxy benchmarks
5 stars 0 forks source link

Add baseline calling method as is #4

Closed dzmitry-lahoda closed 5 years ago

dzmitry-lahoda commented 5 years ago

Add baseline calling method as is from manually written proxy. Mark method called and proxy method which calls with MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization so these are not eliminated.

dzmitry-lahoda commented 5 years ago

New way of declaring classes and lambda expression bodied method allow to write manual proxies faster. And the functional notion of interface segregation principle leads to smaller interfaces. So proxy generators are less needed.

dzmitry-lahoda commented 5 years ago

Seeing these results I believe you can do better. I guess it will be less than 30 ns. May be 25 ns.

                Method |       Mean |      Error |     StdDev | Scaled | ScaledSD |
---------------------- |-----------:|-----------:|-----------:|-------:|---------:|
 UsingManualNoInlining |   4.711 ns |  0.1283 ns |  0.1798 ns |   1.00 |     0.00 |
      UsingLightInject |  37.278 ns |  0.7805 ns |  1.6463 ns |   7.92 |     0.45 |
           UsingCastle |  49.258 ns |  1.0717 ns |  1.5709 ns |  10.47 |     0.51 |
            UsingLinFu | 610.144 ns | 11.8642 ns | 16.6319 ns | 129.69 |     5.94 |
         UsingDispatch | 661.777 ns | 13.1110 ns | 34.5395 ns | 140.67 |     8.98 |
dzmitry-lahoda commented 5 years ago

I hope these people will not found out slowness one day https://twitter.com/roytries/status/1024600855536914432

seesharper commented 5 years ago

Great job @dzmitry-lahoda 👍 We needed that baseline to emphasise the overhead of doing dynamic proxies.

As for performance, I would never use a dynamic proxy in a tight loop. But I would maybe use it to implement a system wide diagnostic tool that can be turned on and off by config. Sort of like a intercept all/profiling kind of thing. In the request pipeline of a web server it would probably not matter all that much. We are talking about 30ns per request and our typical average web request might be in the 30 to 50ms range. Is it negligible? Well, that is up to all of us making decisions about these things 😎

seesharper commented 5 years ago

Closed by #5

dzmitry-lahoda commented 5 years ago

There faster proxy is the more times people will use as always on feature in more situations. I.e. Hegel-Marx move from quantity(faster) to quality(new usages).