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

System.Text.Json support. #101

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open

System.Text.Json support. #101

wants to merge 28 commits into from

Conversation

Quahu
Copy link
Owner

@Quahu Quahu commented Aug 1, 2022

Continued from #100

Because of the overall better performance and no unnecessary LINQ allocations System.Text.Json will replace Newtonsoft.Json in the future. Currently, Newtonsoft.Json is still the default and the serializer service has to be replaced in order to use System.Text.Json:

services.Replace(ServiceDescriptor.Singleton<IJsonSerializer, SystemJsonSerializer>());

Important

SystemJsonSerializer is only available if your application targets .NET 8 and newer.

Some benchmarks

From top to bottom are in order:

  • an older Disqord build (.NET 6) from NuGet
  • a Disqord build (.NET 8) from this branch
  • a Disqord build (.NET 8) using System.Text.Json from this branch

Old Newtonsoft (.NET 6) Build

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
RestApiCallLargeBodyHighLevel 1,655.71 us 31.671 us 40.054 us 46.8750 46.8750 46.8750 754 KB
RestApiCallLargeBodyLowLevel 1,662.00 us 7.340 us 6.129 us 46.8750 46.8750 46.8750 746 KB
RestApiCallEmptyBodyHighLevel 25.74 us 0.504 us 0.656 us 0.1831 - - 10 KB
RestApiCallEmptyBodyLowLevel 23.84 us 0.283 us 0.264 us 0.1831 - - 10 KB
WebSocketLifecycleLargeGuildCreate 930,109.53 us 18,475.223 us 32,839.689 us 8000.0000 4000.0000 1000.0000 435,414 KB

New Newtonsoft (.NET 8) Build

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
RestApiCallLargeBodyHighLevel 1,173.730 us 19.3825 us 18.1304 us 46.8750 46.8750 46.8750 904 KB
RestApiCallLargeBodyLowLevel 1,231.455 us 22.5396 us 36.3973 us 46.8750 46.8750 46.8750 897 KB
RestApiCallEmptyBodyHighLevel 8.632 us 0.4001 us 1.1609 us 0.1831 - - 9 KB
RestApiCallEmptyBodyLowLevel 5.837 us 0.1155 us 0.2169 us 0.1831 - - 9 KB
WebSocketLifecycleLargeGuildCreate 735,406.145 us 14,690.9525 us 42,386.7569 us 9000.0000 8000.0000 1000.0000 460,100 KB

System.Text.Json (.NET 8) Build

Method Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
RestApiCallLargeBodyHighLevel 768.534 us 20.5097 us 60.1514 us 46.8750 46.8750 46.8750 402 KB
RestApiCallLargeBodyLowLevel 714.988 us 8.9789 us 8.3989 us 46.8750 46.8750 46.8750 394 KB
RestApiCallEmptyBodyHighLevel 3.007 us 0.0492 us 0.1070 us 0.0725 - - 4 KB
RestApiCallEmptyBodyLowLevel 3.580 us 0.0712 us 0.0926 us 0.0687 - - 3 KB
WebSocketLifecycleLargeGuildCreate 192,896.364 us 3,717.7621 us 3,295.6993 us - - - 156,412 KB

@Quahu Quahu marked this pull request as ready for review July 29, 2024 16:53
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.

2 participants