Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: optimize CachedRequestBuilder #1716

Merged
merged 3 commits into from
Jun 25, 2024

Conversation

TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Jun 12, 2024

Rewrote CachedRequestBuilder to use a custom MethodTableKey value as a dictionary key instead of a concatenated string. Resulted in some modest memory savings and reduced object usage.

  • Added unit tests to ensure that the dictionary key works correctly.
  • On lines 48 & 49 of CachedRequestBuilderImplementation I copy the arrays to create the dictionary key, this is to prevent the arrays being changed, breaking the dictionary. This can be removed if Refit assumes that the input arrays are not accessible to the user.
  • Implemented IEquatable<MethodTableKey>, implementing my own GetHashCode method. I could have used the recommended HashCode object but it is not available in .NET Framework. I could copy the implementation over and use it if you want.

Original

Method Mean Error StdDev Gen0 Gen1 Allocated
TaskT_Async 16.64 us 0.329 us 0.885 us 1.4038 0.0305 13.04 KB
TaskTLong_Async 17.25 us 0.343 us 0.669 us 1.4954 0.0305 13.82 KB
TaskTGeneric_Async 18.03 us 0.360 us 0.592 us 1.6479 0.0305 15.19 KB

With changes

Method Mean Error StdDev Gen0 Gen1 Allocated
TaskT_Async 12.19 us 0.241 us 0.277 us 1.4038 0.0305 12.92 KB
TaskTLong_Async 13.26 us 0.262 us 0.331 us 1.4648 0.0305 13.51 KB
TaskTGeneric_Async 14.35 us 0.286 us 0.627 us 1.5564 0.0305 14.49 KB

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

Attention: Patch coverage is 82.35294% with 6 lines in your changes missing coverage. Please review.

Project coverage is 84.57%. Comparing base (6ebeda5) to head (70d836a).
Report is 44 commits behind head on main.

Files Patch % Lines
Refit/CachedRequestBuilderImplementation.cs 82.35% 4 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1716      +/-   ##
==========================================
- Coverage   87.73%   84.57%   -3.16%     
==========================================
  Files          33       35       +2     
  Lines        2348     2503     +155     
  Branches      294      325      +31     
==========================================
+ Hits         2060     2117      +57     
- Misses        208      304      +96     
- Partials       80       82       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TimothyMakkison
Copy link
Contributor Author

TimothyMakkison commented Jun 25, 2024

Was this added? I don't see it in the commits for main?

@ChrisPulman ChrisPulman reopened this Jun 25, 2024
@ChrisPulman ChrisPulman merged commit b320e4e into reactiveui:main Jun 25, 2024
1 of 3 checks passed
Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants