reactiveui / refit

The automatic type-safe REST library for .NET Core, Xamarin and .NET. Heavily inspired by Square's Retrofit library, Refit turns your REST API into a live interface.
https://reactiveui.github.io/refit/
MIT License
8.66k stars 744 forks source link

POC: remove unneeeded `Uri` / `UriBuilder` allocations #1914

Closed TimothyMakkison closed 2 weeks ago

TimothyMakkison commented 2 weeks ago

Experiment: move query logic from RequestBuilderImplementation to RestMethodInfo, ecaping as needed.

Demonstrates some suspiciously good memory savings. I imagine this is from not allocating Uri 56 bytes, UriBuilder 88 bytes and calling various Uri methods (variable around 600 bytes). Unfortunately, this is broken under ceratin conditions 🤷 This can be fixed but will require rigorous testing.

Updated (on battery power)

Method Mean Error StdDev Median Gen0 Allocated
ConstantRouteAsync 5.581 us 0.5362 us 1.581 us 5.747 us 0.2060 1.91 KB
DynamicRouteAsync 7.694 us 0.8794 us 2.565 us 7.492 us 0.2289 2.12 KB
ComplexDynamicRouteAsync 10.209 us 0.9911 us 2.922 us 10.531 us 0.2594 2.45 KB
ObjectRequestAsync 15.595 us 2.4077 us 7.099 us 14.759 us 0.3052 3.34 KB
ComplexRequestAsync 23.063 us 0.8777 us 2.343 us 22.049 us 0.9766 9.1 KB

Old

Method Mean Error StdDev Median Gen0 Allocated
ConstantRouteAsync 4.255 us 0.1537 us 0.4507 us 4.422 us 0.2823 2.63 KB
DynamicRouteAsync 4.636 us 0.4640 us 1.3682 us 4.908 us 0.3128 2.91 KB
ComplexDynamicRouteAsync 4.039 us 0.0492 us 0.0437 us 4.045 us 0.3586 3.32 KB
ObjectRequestAsync 4.909 us 0.6689 us 1.8755 us 4.050 us 0.4730 4.35 KB
ComplexRequestAsync 11.812 us 0.0539 us 0.0478 us 11.799 us 1.1292 10.38 KB

dotMemory profile - Divide memory value by 1000 to get the actual allocations

image

github-actions[bot] commented 6 days ago

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.