-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Description
We are working on improving our position in the TechEmpower JSON benchmark.
Our recent changes in the networking stack allowed us to improve the throughput by +20%. But we are slowly getting to the point where we won't be able to optimize it any further and we are looking for some other places that could be improved.
Naturally, one of them can be JSON serialization itself.
As of today, we are spending +- 4.6% of the total CPU time for the JSON serialization in the JSON benchmark. 1% of CPU time translates to circa 10 thousand requests per second.
@steveharter Could you please take a look at the breakdown below and see if there is anything that we could improve?
The breakdown:
The code itself is super simple, it's more or less:
private static readonly JsonSerializerOptions SerializerOptions = new JsonSerializerOptions();
using (Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(writer.Output))
{
JsonSerializer.Serialize<JsonMessage>(utf8JsonWriter, new JsonMessage { message = "Hello, World!" }, SerializerOptions);
}
public struct JsonMessage
{
public string message { get; set; }
}
The actual code can be found in the aspnet/benchmarks repo.
The command required to run the benchmark:
git clone https://github.com/aspnet/Benchmarks.git
cd benchmarks\src\BenchmarksDriver
dotnet run -- --jobs ..\BenchmarksApps\Kestrel\PlatformBenchmarks\benchmarks.json.json --scenario "JsonPlatform"
Every command should contain the address of the server and client machine which you can get from @sebastienros
--server "$secret1" --client "$secret2"
If you want to test how your change in System.Text.Json.dll
(or any other .dll
) affects the performance of the TechEmpower benchmark you need to pass it to the driver:
--output-file "C:\Projects\runtime\artifacts\bin\System.Text.Json\net5.0-Release\System.Text.Json.dll"