refit icon indicating copy to clipboard operation
refit copied to clipboard

BenchmarkDotNet profiler

Open Sergio0694 opened this issue 4 years ago • 3 comments

What kind of change does this PR introduce?

This PR adds a profiler project using BenchmarkDotNet.

What is the current behavior?

There is no built-in profiler.

What is the new behavior?

There is a profiler to benchmark some REST calls on .NET Core 2.1 and 3.1.

What might this PR break? Nothing.

Please check if the PR fulfills these requirements

  • [X] Tests for the changes have been added (for bug fixes / features)
  • [X] Docs have been added / updated (for bug fixes / features)

Other information: cc. @clairernovotny, this PR is still marked as draft for now. I can't figure out how to make the project build with BenchmarkDotNet when refit is directly referenced from the local projects and not through NuGet, could you help with that? I copied/modified the .csproj code from the test project and I can get the profiler to build and run correctly if I run it directly from VS and try to execute one of the benchmarking methods, but if I use just dotnet Refit.Profiler.dll and let BenchmarkDotNet do its thing, it fails to run the benchmark with an error saying the interface in use is not a valid refit interface, which shows the build task is not run correctly I guess? Any help here is welcome 😄

cc. @Dreamescaper - feel free to help out with new benchmarks to add!

NOTE: this PR needs to be merged in before https://github.com/reactiveui/refit/pull/897 so that we can then run comparative benchmarks between the two versions of refit in that other branch before adding those optimizations.

Sergio0694 avatar Apr 08 '20 20:04 Sergio0694

How's this PR doing?

clairernovotny avatar May 19 '20 11:05 clairernovotny

Hey @clairernovotny, so the profiler project is basically ready, but as mentioned above I can't get the BenchmarkDotNet run to work correctly. That is, manually running the benchmark in both Debug/Release mode from VS works just fine, but when running the profiler with dotnet Refit.Profiler.dll (which triggers the BenchmarkDotNet build/run), all runs fail with this error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> Refit.ApiException: Response status code does not indicate success: 404 (No matching mock handler for "GET http://github.com/users/refit.json").
   at Refit.RequestBuilderImplementation.<>c__DisplayClass14_0`2.<<BuildCancellableTaskFuncForMethod>b__0>d.MoveNext() in C:\Users\Sergio\Documents\GitHub\refit_fork\Refit\RequestBuilderImplementation.cs:line 263
--- End of stack trace from previous location where exception was thrown ---
   at BenchmarkDotNet.Autogenerated.Runnable_0.<.ctor>b__3_3() in C:\Users\Sergio\Documents\GitHub\refit_fork\Refit.Profiler\bin\Release\netcoreapp2.1\307006d4-87b1-42df-bfcb-df67874f1ad2\307006d4-87b1-42df-bfcb-df67874f1ad2.notcs:line 185
   at BenchmarkDotNet.Autogenerated.Runnable_0.WorkloadActionNoUnroll(Int64 invokeCount) in C:\Users\Sergio\Documents\GitHub\refit_fork\Refit.Profiler\bin\Release\netcoreapp2.1\307006d4-87b1-42df-bfcb-df67874f1ad2\307006d4-87b1-42df-bfcb-df67874f1ad2.notcs:line 487
   at BenchmarkDotNet.Engines.Engine.RunIteration(IterationData data)
   at BenchmarkDotNet.Engines.EngineStage.RunIteration(IterationMode mode, IterationStage stage, Int32 index, Int64 invokeCount, Int32 unrollFactor)
   at BenchmarkDotNet.Engines.EnginePilotStage.RunAuto()
   at BenchmarkDotNet.Engines.Engine.Run()
   at BenchmarkDotNet.Autogenerated.Runnable_0.Run(IHost host, String benchmarkName) in C:\Users\Sergio\Documents\GitHub\refit_fork\Refit.Profiler\bin\Release\netcoreapp2.1\307006d4-87b1-42df-bfcb-df67874f1ad2\307006d4-87b1-42df-bfcb-df67874f1ad2.notcs:line 168
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at BenchmarkDotNet.Autogenerated.UniqueProgramName.AfterAssemblyLoadingAttached(String[] args) in C:\Users\Sergio\Documents\GitHub\refit_fork\Refit.Profiler\bin\Release\netcoreapp2.1\307006d4-87b1-42df-bfcb-df67874f1ad2\307006d4-87b1-42df-bfcb-df67874f1ad2.notcs:line 50

Any help here? 😅

Sergio0694 avatar May 22 '20 17:05 Sergio0694

A lot has changed in Refit since 2020, including its use of Source Generators. A profiling project would still be most welcome if anyone cares to finish this! :)

clairernovotny avatar Jan 19 '22 15:01 clairernovotny

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Apr 27 '23 00:04 github-actions[bot]