Skip to content

Conversation

@EzrealJ
Copy link
Collaborator

@EzrealJ EzrealJ commented Dec 15, 2025

添加 RestSharp 作为新的 HTTP 客户端基准测试工具
在多个请求类型中实现 RestSharp 的基准测试方法
配置 RestSharp 客户端服务并添加相关包装类

Summary by CodeRabbit

  • New Features
    • Added RestSharp-based benchmarks for GET, POST (JSON & XML), and PUT form scenarios.
    • Integrated RestSharp as an additional HTTP client option in the benchmark suite for side-by-side performance comparisons.

✏️ Tip: You can customize this high-level summary in your review settings.

添加 RestSharp 作为新的 HTTP 客户端基准测试工具
在多个请求类型中实现 RestSharp 的基准测试方法
配置 RestSharp 客户端服务并添加相关包装类
@coderabbitai
Copy link

coderabbitai bot commented Dec 15, 2025

Walkthrough

Adds RestSharp to the benchmarks project, registers two RestSharp wrapper clients in GlobalSetup, and introduces RestSharp-based benchmark methods for GET/POST/PUT with JSON, XML, and form payloads mirroring existing benchmark patterns.

Changes

Cohort / File(s) Summary
RestSharp setup & DI
WebApiClientCore.Benchmarks/Requests/Benchmark.cs, WebApiClientCore.Benchmarks/WebApiClientCore.Benchmarks.csproj
Adds RestSharp package reference, adds using RestSharp, defines public nested wrapper classes RestSharpJsonClient : RestClient and RestSharpXmlClient : RestClient, and registers them with response handlers and base addresses during GlobalSetup.
GET benchmarks
WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs, WebApiClientCore.Benchmarks/Requests/HttpGetJsonBenchmark.cs
Adds RestSharp_GetAsync() and RestSharp_GetJsonAsync() which create a scope, resolve RestSharpJsonClient, build a RestRequest to /benchmarks/id001, and execute it asynchronously (raw and typed).
POST benchmarks (JSON / XML)
WebApiClientCore.Benchmarks/Requests/HttpPostJsonBenchmark.cs, WebApiClientCore.Benchmarks/Requests/HttpPostXmlBenchmark.cs
Adds RestSharp_PostJsonAsync() and RestSharp_PostXmlAsync() that resolve RestSharpJsonClient/RestSharpXmlClient, build requests with JSON or XML bodies, and post asynchronously returning User.
PUT form benchmark
WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs
Adds RestSharp_PutFormAsync() that resolves RestSharpJsonClient, constructs a form-encoded RestRequest with multiple form parameters and content-type header, and calls PutAsync<User>().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus review on:
    • Benchmark.cs GlobalSetup: DI registrations, response handler wiring, base addresses.
    • Public nested classes RestSharpJsonClient and RestSharpXmlClient (visibility and inheritance).
    • New benchmark methods: correct RestSharp request construction, generic usage for typed responses, and content-type/serialization for JSON, XML, and form payloads.

Poem

🐰 I padded through code with a nimble hop,
Added RestSharp friends to test and to stop.
GETs and POSTs, XML and JSON delight,
I benchmark by day and dream in bytes by night. 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding RestSharp benchmark support to the benchmarks project. It is concise, specific, and directly related to the changeset which introduces RestSharp integration across multiple benchmark files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 10405e9 and ad6935a.

📒 Files selected for processing (1)
  • WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs (1)
WebApiClientCore.Benchmarks/User.cs (2)
  • User (8-49)
  • User (43-48)
🔇 Additional comments (2)
WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs (2)

3-3: LGTM!

The RestSharp using directive is correctly added to support the new benchmark method.


26-39: No action needed - code is correct.

RestSharp's PutAsync<T> method returns Task<T>, not Task<RestResponse<T>>. The method signature correctly matches the return type. Async methods named after HTTP methods (like PutAsync) return Task<T> instead of Task<RestResponse<T>>.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs (1)

26-33: Consider using explicit HTTP method for clarity.

The benchmark uses ExecuteAsync without explicitly specifying the HTTP method. While RestRequest defaults to GET, consider using GetAsync() or explicitly setting the method for better readability and consistency with other RestSharp benchmarks.

Apply this diff to use the explicit GET method:

-            var request = new RestRequest($"/benchmarks/id001");
-            await client.ExecuteAsync(request);
+            var request = new RestRequest($"/benchmarks/id001");
+            await client.GetAsync(request);
WebApiClientCore.Benchmarks/Requests/HttpPostXmlBenchmark.cs (1)

4-6: Remove unused imports.

The System.Net.Http (line 4) and System (line 6) namespaces don't appear to be used in this file.

Apply this diff to remove the unused imports:

 using BenchmarkDotNet.Attributes;
 using Microsoft.Extensions.DependencyInjection;
 using RestSharp;
-using System.Net.Http;
 using System.Threading.Tasks;
-using System;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61acf46 and 12d42bb.

📒 Files selected for processing (7)
  • WebApiClientCore.Benchmarks/Requests/Benchmark.cs (3 hunks)
  • WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs (2 hunks)
  • WebApiClientCore.Benchmarks/Requests/HttpGetJsonBenchmark.cs (2 hunks)
  • WebApiClientCore.Benchmarks/Requests/HttpPostJsonBenchmark.cs (2 hunks)
  • WebApiClientCore.Benchmarks/Requests/HttpPostXmlBenchmark.cs (2 hunks)
  • WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs (2 hunks)
  • WebApiClientCore.Benchmarks/WebApiClientCore.Benchmarks.csproj (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs (4)
WebApiClientCore.Benchmarks/Requests/HttpGetJsonBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (18-24)
  • Benchmark (26-33)
WebApiClientCore.Benchmarks/Requests/HttpPostJsonBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (19-25)
  • Benchmark (27-35)
WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (18-24)
  • Benchmark (26-40)
WebApiClientCore.Benchmarks/Requests/Benchmark.cs (4)
  • Task (99-108)
  • Task (114-123)
  • RestSharpJsonClient (127-132)
  • RestSharpJsonClient (129-131)
WebApiClientCore.Benchmarks/Requests/HttpPostXmlBenchmark.cs (3)
WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (18-24)
  • Benchmark (26-33)
WebApiClientCore.Benchmarks/Requests/HttpPostJsonBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (19-25)
  • Benchmark (27-35)
WebApiClientCore.Benchmarks/Requests/Benchmark.cs (4)
  • Task (99-108)
  • Task (114-123)
  • RestSharpXmlClient (135-140)
  • RestSharpXmlClient (137-139)
WebApiClientCore.Benchmarks/Requests/HttpPostJsonBenchmark.cs (1)
WebApiClientCore.Benchmarks/Requests/Benchmark.cs (2)
  • RestSharpJsonClient (127-132)
  • RestSharpJsonClient (129-131)
WebApiClientCore.Benchmarks/Requests/HttpPutFormBenchmark.cs (1)
WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (18-24)
  • Benchmark (26-33)
WebApiClientCore.Benchmarks/Requests/HttpGetJsonBenchmark.cs (2)
WebApiClientCore.Benchmarks/Requests/HttpGetBenchmark.cs (3)
  • Benchmark (10-16)
  • Benchmark (18-24)
  • Benchmark (26-33)
WebApiClientCore.Benchmarks/User.cs (2)
  • User (8-49)
  • User (43-48)
🔇 Additional comments (6)
WebApiClientCore.Benchmarks/Requests/HttpPostJsonBenchmark.cs (1)

27-35: LGTM!

The RestSharp POST JSON benchmark implementation is correct and follows the established pattern. The use of AddJsonBody and PostAsync<User> appropriately mirrors the existing Refit and WebApiClientCore benchmarks.

WebApiClientCore.Benchmarks/Requests/HttpPostXmlBenchmark.cs (1)

28-36: LGTM!

The RestSharp POST XML benchmark correctly uses AddXmlBody and PostAsync<User>, maintaining consistency with the other benchmark implementations.

WebApiClientCore.Benchmarks/Requests/HttpGetJsonBenchmark.cs (1)

26-33: LGTM!

The RestSharp GET JSON benchmark is well-implemented using GetAsync<User>, which properly deserializes the response and maintains consistency with the existing Refit and WebApiClientCore patterns.

WebApiClientCore.Benchmarks/Requests/Benchmark.cs (3)

61-83: LGTM!

The RestSharp client configuration properly integrates with the existing HttpClientFactory pattern. The setup correctly:

  • Registers named HttpClients with appropriate response handlers
  • Uses transient lifetime for RestSharp clients
  • Leverages IHttpClientFactory for proper HttpClient management

126-140: LGTM!

The RestSharp wrapper classes are appropriately simple, serving as thin adapters that pass the managed HttpClient to RestClient's base constructor. This design allows RestSharp to participate in the benchmark while respecting the HttpClientFactory pattern.


92-93: LGTM!

The warmup calls for RestSharp clients follow the existing pattern for Refit and WebApiClientCore clients, ensuring all clients are initialized before benchmarking begins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant